HR HR
asked 9 years ago

Hi, we have a certain category of posts. Whenever the user views a single post of that category (single.php) we want the rightmost sidebar of focus and the top wordpress menu to be hidden. This is what I tried but to no avail:
I found out the ID code of the category;
in single.php I changed this line
<?php get_sidebar( ‘single’ ); ?>
To:
<?php if ( !( is_category(‘6713‘) ) ) { ?>
<?php get_sidebar( ‘single’ ); ?>
<?php } ?>

and in header.php I changed:
wp_nav_menu($params);

To:
?php if ( !( is_category(‘6713‘) ) ) { ?>
<?php wp_nav_menu($params); ?>
<?php } ?>
But this simply doesn’t work, the code is ignored, I think the is_category (or in_category, I also tried) simply always returns FALSE or something like that, because it isn’t in the scope of the inside category variable that would return a proper answer. That’s my theory (because when I put a hard coded condition in the IF, such as IF 3>4, this does work) How can I do this simply, without creating custom types, custom DW FOCUS template copies, or the like? its just a very simple change, I don’t want to make a mountain out of it.
Thanks

PS Using WordPress 3.9.1 and focus 1.0.8

1 Answers
DominicStaff
answered 9 years ago

Hi,
To disable sidebar & wordpress menu in specific post, you can add the following code to the functions.php file.

add_filter( ‘sidebars_widgets’, ‘disable_sidebar_widgets’ );
function disable_sidebar_widgets( $sidebars_widgets ) {
if (is_single(array(115,555,…,…,)))
$sidebars_widgets = array( false );
return $sidebars_widgets;
}

function wpsites_remove_admin_bar() {
if ( is_single(115,555,…,…,) ):
show_admin_bar(false);
endif;
}
add_action(‘wp_head’, ‘wpsites_remove_admin_bar’);

To css for specific post that you have disabled sidebar, you can add the following code to the style.css file.
Note: You need change the post ID in the following code (e.g: 115):

.postid-115 #main>.container>.row {
background: none;
}
.postid-115 .span9 {width: 1040px; }
@media (min-width: 980px) and (max-width: 1079px) {
.postid-115 .site-content>.hentry .entry-content {
width: 760px !important;
}
.postid-115 .span9 {
width: 770px !important;
}
}
@media (max-width: 979px) {
.postid-115 .site-content>.hentry .entry-content {
width: 100% !important;
}
.postid-115 .span9 {
width: 100% !important;
}
}
@media (min-width: 599px) and (max-width: 979px) {
.postid-115 .span9 {
width: 100% !important;
}
}
.postid-115 .site-content>.hentry .entry-content {
max-width: 830px;
width: 840px;
}

Hope this helps !
 

HR HR
replied 9 years ago

Hi, much obliged for this… but what we wanted was to do those things (hide these elements) not for posts of any specific ID, but for all posts under a specific category ID…. how would that be done with this code… thanks

Powered by DW Question & Answer Pro