[resolved] Display posts from a specific category (4 posts)

  1. Zane
    Posted 3 years ago #

    Hi there,

    I recently discovered code (from Sitepoints Wicked WordPress Themes) that allows for the latest 4 posts to be displayed on a page. The code sits in the functions file and is then called within the page.

    function wicked_indexloop() {
      if (have_posts()) : while (have_posts()) : the_post(); ?>
        ⋮ we'll do some stuff here
      <?php endwhile; else: ?>
        ⋮ if there are no posts, we'll display an error
      <?php endif;

    How can I modify this to display the 4 latest posts from a specific category?

  2. pedjas
    Posted 3 years ago #

    Use something like: query_posts('cat=3&posts_per_page=4')

    That should return last four posts from category 3.

  3. kepbem
    Posted 3 years ago #

    This works for me, where 'Gallery' is the name of the category I'm looking to display -
    : query_posts( 'Gallery' );

  4. Zane
    Posted 3 years ago #

    Great, thanks! I will give them both a try and see what happens;)

Topic Closed

This topic has been closed to new replies.

About this Topic