Hi there,
I have trouble with hiding sidebar from page that list my custom post type posts.
Here is example of config, neither of this works.
I have:
Custom post type (post) named: case_study
Custom page template: page-our-work.php (Template name: Our Work)
Page with Title: Our Work, Slug: our-work, ID: 28 that uses template ‘Our Work’
Sidebar is hidden from all pages, but is only visible on this page, and I don’t seem to find a solution to hide it.
array(
'is_404',
'is_page',
'is_front_page',
array('is_singular', array('case_study') ),
array('is_singular', array('custom-post-type')),
array('is_page', 28 ),
array('is_page', array( 'our-work' ) ),
array('is_page', array( 'Our Work' ) ),
array('is_page', array( 28, 'our-work' ) ),
array('is_page', array( 28, 'Our Work' ) ),
array('is_page', array( 28, 'our-work', 'Our Work' ) ),
array('is_page', array('case_study') ),
array('is_page', array('custom-post-type')),
array('is_page_template', array('page-our-work.php')),
),
/**
* Page template checks (via is_page_template())
* Any of these page templates that return true won't show the sidebar
*/
array(
'page-our-work.php'
)
bobz_zg
October 30, 2013, 10:37am
2
I have found a solution by adding array( 'is_post_type_archive', array( 'case_study') )
$sidebar_config = new Roots_Sidebar(
array(
'is_404',
'is_page',
'is_front_page',
array( 'is_post_type_archive', array( 'case_study') ),
array( 'is_singular', array('case_study') ),
),
array(
'page-our-work.php'
)
);
Foxaii
October 30, 2013, 10:50am
3
I’m glad you found your solution. For future reference there’s a useful overview of the different Conditional Tags in the codex.
bobz_zg
October 30, 2013, 11:42am
4
Yeah, me to
I know about that, it just took me some time to find correct function
Cheers
hi guys, i just saw this solution it’s great.
I want to add that if you need to hide the sidebar on the category and single of a custom post you can make your own function.
For example, im using this
function is_cpt_return(){
if ( get_post_type() == ‘my_cpt_name’ )
return true;
else
return false;
}
Then i call it
array(
‘is_404’,
‘is_page’,
‘is_front_page’,
‘is_cpt_return’
),
array(
‘page-our-work.php’
)
1 Like
I also want to put it out there if you’re hiding the sidebar on almost every single page that you can switch the logic in lib/sidebar.php so that the default is to hide the sidebar vs. show it. Then you would use your same conditionals to show the sidebar instead.
Check it out:
class Roots_Sidebar {
private $conditionals;
private $templates;
public $display = false;
function __construct($conditionals = array(), $templates = array()) {
$this->conditionals = $conditionals;
$this->templates = $templates;
$conditionals = array_map(array($this, 'check_conditional_tag'), $this->conditionals);
$templates = array_map(array($this, 'check_page_template'), $this->templates);
if (in_array(true, $conditionals) || in_array(true, $templates)) {
$this->display = true;
}
}
private function check_conditional_tag($conditional_tag) {
if (is_array($conditional_tag)) {
return $conditional_tag[0]($conditional_tag[1]);
} else {
return $conditional_tag();
}
}
private function check_page_template($page_template) {
return is_page_template($page_template);
}
}
1 Like
duard
August 24, 2014, 8:08pm
7
Same problem here
<?php
/*
Template Name: Template Vehicles
*/
?>
<?php query_posts( 'posts_per_page=9&post_type=vehicle&paged=' . $paged ); ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_title(); ?>
<?php endwhile; ?>
if I put this line
<?php query_posts( 'posts_per_page=9&post_type=vehicle&paged=' . $paged ); ?>
then my sidebar show in this template
duard
August 24, 2014, 8:16pm
8
I fix it with <?php wp_reset_query();?>