• 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 wordpress 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. But this is a fundamental wordpress issue, I believe.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hey there rsspanic.

    Hope you’re well! ??

    I think what you need is https://codex.www.ads-software.com/Function_Reference/in_category NOT https://codex.www.ads-software.com/Function_Reference/is_category since it is for checking if a Category archive page is being displayed.

    Let me know if it helps! ??

    Take care,
    Calvin

    Thread Starter rsspanic

    (@rsspanic)

    Hi, thanks but I already tried it… I think in that place in the code the _category function just doesn’t… function… could it be?

    Here’s my single.php

    Thanks for any help…

    <?php
    /**
    * The Template for displaying all single posts.
    */

    get_header(); ?>

    <div id=”…etc”>

    <?php while ( have_posts() ) : the_post(); ?>

    <?php get_template_part( ‘content’, ‘single’ ); ?>

    <?php endwhile; // end of the loop. ?>

    <?php
    $tags = wp_get_post_tags( get_the_ID() );

    if ($tags) {
    $tag_ids = array();
    foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
    $args=array(
    ‘tag__in’ => $tag_ids,
    ‘post__not_in’ => array(get_the_ID()),
    ‘posts_per_page’=>3, // Number of related posts to display.
    ‘ignore_sticky_posts’=>1
    );
    $my_query = new WP_Query( $args );

    }
    ?>

    <?php while ( have_posts() ) { the_post(); ?>
    <?php comments_template( ”, true ); ?>

    <?php } ?>
    </div>

    <?php if ( !( in_category(‘6713‘) ) ) { ?>
    <?php get_sidebar( ‘single’ ); ?>
    <?php } ?>

    <?php get_footer(); ?>

    Hey there rsspanic,

    You’re welcome and happy to help! ??

    Replace the code ( not all just the one that using the in_category ) with this:

    <?php if ( in_category(‘6713‘, $my_query->ID) == false ) : ?>
    <?php get_sidebar( 'single' ); ?>
    <?php endif; ?>

    Also make sure that you don’t have violating code before this. It might affect result.

    Let me know if it helps! ??

    Take care,
    Calvin

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hide sidebar and top menu in posts of a certain category’ is closed to new replies.