WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] 2 full posts, 18 excerpts (3 posts)

  1. Anna
    Member
    Posted 3 years ago #

    Which is working great. Except I was wondering how I might be able to insert a
    <ul> and </ul>
    for the 18 excerpts without having it repeat for each one?

    Much thanks in advance for help!

    Code is here:

    <div id="maincontenttop"></div>
    <div id="maincontent">
    <?php query_posts ('cat=1&posts_per_page=20'); if (have_posts()) : $count = 0; while (have_posts()) : the_post(); $count++; ?>
    <?php if ($count <= 2) : ?>
    <div class="postcontainer">
    <h2><?php the_time('m.d.y.') ?> <?php the_title(); ?></h2>
    <?php the_content(); ?>
    </div>
    <?php else : ?>
    <li><?php the_time('m.d.y.') ?> <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
    
    <?php endif; ?>
    <?php endwhile; ?>
    <?php else : ?>
    <?php endif; ?>
    </div>
    <div id="maincontentbot"></div>
  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    if count is 3 then insert the ul tag;
    after the loop, if count is 3 or more, close the ul tag:

    <?php if ($count <= 2) : ?>
    <div class="postcontainer">
    <h2><?php the_time('m.d.y.') ?> <?php the_title(); ?></h2>
    <?php the_content(); ?>
    </div>
    <?php else : ?>
    <?php if( $count == 3 ) echo '<ul>'; ?>
    <li><?php the_time('m.d.y.') ?> <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
    
    <?php endif; ?>
    <?php endwhile; ?>
    <?php if( $count >= 3 ) echo '</ul>'; ?>

    -untested-

  3. Anna
    Member
    Posted 3 years ago #

    Worked perfectly. Thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.