Forums

[resolved] List 5 most recent post of a category on main page (3 posts)

  1. erochow
    Member
    Posted 2 years ago #

    hi everyone,

    I'd like to have a list of the 5 most recent posts of a particular category on the main page of my WP site, http://gardenfork.tv

    I tried to use the Recent Posts Embed plug in, but no luck. I believe this can be done with template tags.

    But being a newbie to coding, i'm looking for help in formulating the code to drop into the Main Index Page .

    i'd like to list the 5 most recent posts for the Recipes category, and have each of those posts listed to be linked back to that specific post.

    thanks for your help, eric.

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    <?php
        $args=array(
          'cat' => 6,
          'showposts'=>5,
          'caller_get_posts'=>1
        );
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          echo '5 recent Posts';
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
           <?php
          endwhile;
        } //if ($my_query)
      wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  3. erochow
    Member
    Posted 2 years ago #

    wow. thanks for the super fast response. best, eric.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags