in_category() stops working correctly once addl get_posts() is added
-
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
- The topic ‘in_category() stops working correctly once addl get_posts() is added’ is closed to new replies.