WordPress.org

Ready to get started?Download WordPress

Forums

custom loop w/ customized first post (2 posts)

  1. hirezolution
    Member
    Posted 1 year ago #

    hey guys

    im trying to set up a custom query on a static page to display the 5 most recent posts, with a customized first post (unique class and code).

    the code i've come up with thus far takes care of customizing my first post, but doesn't define post count. i only want to display 5, i want to set a greater number for the actual blog page. make sense?

    here's what i've pieced together so far w/ minimal php expertise. any ideas?

    <?php if (have_posts()) : ?>
    <?php $post = $posts[0]; $c=0;?>
    <?php while (have_posts()) : the_post(); ?>
    
    <?php $c++;
    if( !$paged && $c == 1) :?>
    <li class="first post">
    <?php the_post_thumbnail(); ?>
    <h2><?php if (strlen($post->post_title) > 35) {
    echo substr(the_title($before = '', $after = '', FALSE), 0, 35) . '...'; } else {
    the_title();
    } ?></h2>
    <?php the_excerpt(); ?>
    </li>
    
    <?php else :?>
    <li class="post">
    <?php the_post_thumbnail(); ?>
    <h2><?php if (strlen($post->post_title) > 35) {
    echo substr(the_title($before = '', $after = '', FALSE), 0, 35) . '...'; } else {
    the_title();
    } ?></h2>
    <?php the_excerpt(); ?>
    </li>
    <?php endif;?>
    
    <?php endwhile; ?>
    
    <?php endif; ?>
  2. s_ha_dum
    Member
    Posted 1 year ago #

    You need to use get_posts() and define a 'numberposts' parameter. That will allow you to choose your post count for this loop only and set the site default to something else.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags