WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to show recent posts EXCEPT the latest? (3 posts)

  1. jamesinternet
    Member
    Posted 2 months ago #

    Hi,

    Right now I'm working on a custom theme for a personal site: http://shakeydesigns.com/wp/

    As you can see on the main page I have the latest article displayed in full and underneath there are links to the three most recent posts.

    This is generally what I'm going for, but it's rather redundant to have a link to the post the reader just read.

    Right now it goes:

    FULL TEXT OF MOST RECENT ARTICLE
    Link to most recent article
    Link to 2nd most recent article
    Link to 3rd most recent article

    How do I change the recent posts to show the 3 most recent posts, EXCEPT for the very latest one? In other words:

    FULL TEXT OF MOST RECENT ARTICLE
    Link to 2nd most recent article
    Link to 3rd most recent article
    Link to 4th most recent article

    This is the code for the links I'm using right now:

    <?php
        $args=array(
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => 3,
          'caller_get_posts'=> 1
          );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <div id=title><h1 style="font-size: 18pt;"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1></div><div id=content><div class=catslug style="padding-left: 50px; padding-right: 50px;"><?php if (function_exists('the_subheading')) { the_subheading(); } ?><br><span class=date><?php the_time('l, F j, Y') ?></span></div></div>
           <?php
          endwhile;
        }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
  2. alchymyth
    The Sweeper & Moderator
    Posted 2 months ago #

    you could use the 'offset' parameter in the query; http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters

    however, 'offset' will not work together with pagination if plan to add this at a later stage.

    alternative, consider to capture the ID of the latest post (particular if the post's code is in the same template) and use it with the 'post__not_in' parameter in the query; http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters

    also review http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action

  3. jamesinternet
    Member
    Posted 2 months ago #

    No plans to add pagination so your first suggestion worked like a charm. Thanks so much!

Reply

You must log in to post.

About this Topic