• Hello everyone,

    I’d like to display my latest post in my loop a little different than the rest. I’d like to get to a solution without using post_per_page or showposts.

    This my code:

    <?php query_posts('cat=21'); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>,
    <?php endwhile; else: ?>
    <?php endif; wp_reset_query(); ?>

    As you can see there is a ‘,’ at the end of the link in the loop. In the latest post that is suppost to be ‘.’.

    Hoping for help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I’d like to get to a solution without using post_per_page or showposts.

    then use $wp_query->post_count; and a counter;

    or:

    <?php query_posts('cat=21'); if ( have_posts() ) : $sep = ''; while ( have_posts() ) : the_post(); ?>
    <?php echo $sep; $sep = ', '; ?><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    <?php endwhile; echo '.'; else: ?>
    <?php endif; wp_reset_query(); ?>

    Thread Starter Jeffrey van Rossum

    (@jeffreyvr)

    Thanks for your answer alchymyth. The output is like this now:

    Word , Word2 , Word3 .

    There is a space between both sides of the comma. I would like it to be like this: Word, Word2, Word3.

    I feel a bit silly asking but I can’t figure out where that space comes from.

    the linebreak after
    ...?></a>
    seems to be causing it;

    try and add this section as in one line:
    <?php echo $sep; $sep = ', '; ?><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a><?php endwhile; echo '.'; else: ?>

    Thread Starter Jeffrey van Rossum

    (@jeffreyvr)

    Close call. Tried that, but didn’t help.

    But… when I putted the whole code on one line it did. ??

    Thanks you very much for your help and your very fast response time!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Last post in a loop’ is closed to new replies.