• Resolved gbrown88

    (@gbrown88)


    Hello,

    Have a weird situation going on with in_category that I can’t seem to figure out, so any help would be great. Here’s the situation:

    I currently am using in_category in 5 places on my site where depending on the category, different content is displayed in those areas.

    1 of the spots is in the header before the Loop and the other 4 are in the Sidebar and Footer after the Loop.

    The 1st one, when I place is above my header area, it works fine. When I move it below the header (where I ideally want it), it doesn’t work.

    Same code in each area, any thoughts?

    Thanks

Viewing 10 replies - 1 through 10 (of 10 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Are you using it inside the loop? If not you have to pass it the post ID:
    http://codex.wordpress.org/Function_Reference/in_category

    // post ID 34
    if(in_category('fruit', 34)){ ... }

    Thread Starter gbrown88

    (@gbrown88)

    How can I dynamically pass the post id through?

    I tried adding, $post->ID in the area you place 34 and that didn’t work.

    Thanks

    Moderator keesiemeijer

    (@keesiemeijer)

    On what template file are you using this? The post object is available outside the loop in single.php and page.php:
    in_category('fruit', $post->ID)

    Thread Starter gbrown88

    (@gbrown88)

    I’m using the Genesis Framework.

    I’m running it on is_single only though, in an area designated ‘genesis_before_content_sidebar_wrap’.

    When I have it in ‘genesis_before_header’ it works fine. Same code.

    Moderator keesiemeijer

    (@keesiemeijer)

    Maybe you need to get the global $post value outside the loop. try this:

    global $post;
    if (in_category('fruit', $post->ID)){...}

    Does the theme query the loop in single.php?

    Thread Starter gbrown88

    (@gbrown88)

    I’ll try this. What’s odd is that the other 4 areas, using the same code are working perfectly.

    Thread Starter gbrown88

    (@gbrown88)

    Yeah, that didn’t work. This is what I tried:

    if(is_single()) {
    		global $post;
    		if (in_category('fruit', $post->ID)) { ?>
    
                             //Do Stuff
    
    <?php } else { ?>
    
            //Do Stuff
    
       	<?php }
    	}

    what template?
    does the template use any custom query?
    if so, is the query reset after the loop?

    Thread Starter gbrown88

    (@gbrown88)

    That’s exactly it! Thanks @alchymyth.

    I have a couple custom quereis in a drop down of the Navigation bar.

    Thanks

    Moderator keesiemeijer

    (@keesiemeijer)

    I’m sorry but I’m not that familiar with the Genesis Framework. did you ask at their forums?

    Try echoing the post ID (for troubleshooting):

    global $post;
    echo 'post ID = ' .  $post->ID;

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘in_category Working on Part of Page, Not Rest’ is closed to new replies.