• Resolved zedagent

    (@zedagent)


    I have a simple template which inserts a CSS class depending which category a post is in.

    You can see it in action here:

    https://www.fbala.com/category/press/

    You can see the single post on that page. If you click the title of the post to take you to a single post page, the highlighting on the right is incorrect. ‘Events’ is highlighted when ‘Press’ should be, as this post is in the press category. The code I’m using to make that distinction is simple as can be:

    <a href="/events/"<?php if (in_category('events')) echo ' class="currentsection"';?>>Events</a>
    <a href="/press/"<?php if (in_category('press')) echo ' class="currentsection"';?>>Press</a>

    This was working as intended up until I implemented the recent post ‘newsflash’ box at top. Here’s the code for that:

    <?php $myposts = get_posts('numberposts=2&cat=4,3');
    foreach($myposts as $post):  ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title();?></a></li>
    <?php endforeach; ?>

    If I remove that code, the ‘Press’ navigation link highlights as it should on the single post page.

    Any ideas?

    Thanks for your time,

    Adam

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try adding <?php wp_reset_query();?> to the end of that plugin code.

    Thread Starter zedagent

    (@zedagent)

    You sir are a scholar and a gentleman. Had a feeling it was something along those lines (I’d tried refreshing the post cache after the query but that didn’t do the trick.) Thank you!

    -A

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘in_category() stops working correctly once addl get_posts() is added’ is closed to new replies.