WordPress.org

Support

Support » How-To and Troubleshooting » custom loop w/ customized first post

custom loop w/ customized first post

  • 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; ?>
Viewing 1 replies (of 1 total)
  • 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.

Viewing 1 replies (of 1 total)
  • The topic ‘custom loop w/ customized first post’ is closed to new replies.
Skip to toolbar