Display posts from a category on a page

Display posts from any category on a page so you can make use of conditional menu highlighting.

The need for this arose when I wanted to have a menu item called “news” on a WordPress site used as a CMS. We all know that it’s not easy to integrate a post category into your pages menu. What you could do is add a page called “news” and use a plugin to redirect the page to the category you want to show.

There is just one problem. As soon as you are redirected to a category, the built-in conditional menu highlighting doesn’t work anymore. Meaning that even if you were reading “news”, the menu item “news” in you menu wouldn’t be highlighted.

So this code displays the posts from your news-category but on a page (page.php or your own custom page template) and you can now enjoy the benefits of menu highlighting.

$displayposts = new WP_Query();
  //get posts from your news category
while ($displayposts->have_posts()) : $displayposts->the_post();
<?php the_content('read more...'); ?>
<?php edit_post_link('edit', '', ''); ?>
<?php endwhile; ?>

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!