WordPress.org

Support

Support » How-To and Troubleshooting » How to display (in a page or post) latest posts from a given category

How to display (in a page or post) latest posts from a given category

  • I tried the following code (from the WordPress Loop guide:
    http://codex.wordpress.org/The_Loop)

    <?php $temp_query = $wp_query; ?>
    <!– Do stuff… –>

    <b>Latest Post from Category X:</b>
    <?php query_posts(‘category_name=categoryx&showposts=1’); ?>
    <?php while (have_posts()) : the_post(); ?>
    <!– Do special_cat stuff… –>
    <?php endwhile; ?>

    <?php $wp_query = $temp_query; ?>

    and this did not seem to work. Can anyone please help describe a way to me that would allow the display of the latest X number of posts from a given category, either to display in a page, post, or sidebar?

    Thousand thanks. : )

Viewing 1 replies (of 1 total)
  • either to display in a page, post, or sidebar?

    Make up your mind. Which one?
    – Obviously “in a post” is a nonsense, so let’s not talk about it.
    Pages are not meant to display posts…

    the remaining option is the sidebar. There are million topics here in the forum discussing all the same, so you could find a working version of that code from above.

    An alternative would be a plugin that does it nicely for you, e.g.

    Customizable Post Listings

Viewing 1 replies (of 1 total)
  • The topic ‘How to display (in a page or post) latest posts from a given category’ is closed to new replies.
Skip to toolbar