WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Zane
    Member
    Posted 2 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() {
      query_posts("posts_per_page=4");
      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;
      wp_reset_query();
    }

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

  2. pedjas
    Member
    Posted 2 years ago #

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

    That should return last four posts from category 3.

  3. kepbem
    Member
    Posted 2 years ago #

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

  4. Zane
    Member
    Posted 2 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