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

  1. jpxwordpress
    Posted 8 years ago #

    I tried the following code (from the WordPress Loop guide:

    <?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. : )

  2. moshu
    Posted 8 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic