List Posts in a category and highlight the current post
-
The code below can be used in any template to list the posts from a specific category on a specific category page.
It reads as “If you’re viewing a post in category 4 then show all the posts (‘numberposts=-1’ = show all posts.) in category 4 and highlight the current post as ‘current_post_item’ You can then add another rule for another category below that and so on. (this example shows categories 4,5,6)
it will not display anything if you’re not on a category page.The current page highlighting has to be used out of the loop so it can’t be used from within a widget (using exec php for example) but it can be called as a php include from within a template page. I’m using it below my primary widget area.
[code moderated - for code over 10 lines long, please use the pastebin - see forum guidelines for posting code]
You can use CSS to highlight the 'current_post_item' class.
- The topic ‘List Posts in a category and highlight the current post’ is closed to new replies.