• Hello again! πŸ™‚

    This time.. I’m trying something more advanced. On my homepage I’m listing excerpt posts and I’m trying to exclude the first post.

    This reason for this is that I’m using a template tag query post:

    query_posts('posts_per_page=5');

    to show the most recent post as content and I won’t be needing it to reappear as excerpt.

    Is there any way to make this happen?

    I found this code that excludes a certain post but maybe there’s something I can put in for the first post only..?

    <?php if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == '179' ) continue; ?>
    <?php the_content();?>
    <?php endwhile;endif;?>

    and I also found this code for the first post

    <?php if ($post != 'set') { echo 'firstPost'; $post='set'; } ?>

    but I just don;t know how to attach them all πŸ™

Viewing 3 replies - 1 through 3 (of 3 total)
  • I think this will do what you want:

    <?php $count = 1; ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); if( 1 == $count++ ) continue; ?>
    <?php the_content();?>
    <?php endwhile;endif;?>

    Thread Starter virgild

    (@virgild)

    Hmm, I added it but nothing happened.

    This is my homepage.php

    <?php
    /*
    Template Name: Homepage
    */
    
    get_header(); ?>
    
    <div id="content">
    <div id="leftcolumn">
    
    <div class="posthome">
    
    <?php query_posts('posts_per_page=1'); ?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <?php the_content(__('Read more'));?>
    <?php endwhile; else: ?>
    
    <?php endif; ?>
    
    <?php
    $args=array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => 6,
    'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
    echo '<div id="titlebox"><div class="title">Recent Posts</div></div>';
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    <div class="headingbox">
    <h3 class="smalltext">
    " rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></h3>
    <h4 class="floatright"><?php the_time('F j, Y'); ?> | " rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">Read All</h4></div>
    
    <?php the_excerpt();?>
    
    <hr />
    
    <?php
    endwhile;
    }
    wp_reset_query(); // Restore global post data stomped by the_post().
    ?>
    
    <div class="postclear"></div>
    <div class="postbottomhome"></div>
    
    </div><!-- end #post-->
    
    </div>
    
    </div><!-- end #content-->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    Try the Codex page on ‘The Loop’, especially the section titled ‘Multiple Loops in Action’ for a different approach.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Exclude first recent post’ is closed to new replies.