• I am using the following code to display the image links of the five most recent additions. I’ve got two problems. First, because the post number occurs after the loop is started, I’m having a hard time situating my divs.

    <?php while (have_posts()) : the_post(); ?>
    <?php if ( $i < 6 ) { ?>

    Then float images from first five posts.

    <?php } elseif ( $i > 5 ) { ?>

    Then display the rest of the posts in a different format.

    <?php } ?>
    <?php $i=$i+1; ?>
    <?php endwhile; ?>

    There needs, I think, to be a containing box for the floating divs for the first five posts, but when I put the div outside of the loop, it affects the ones after 5. If I put the div inside the loop, affecting only the individual posts, then I have an issue with the containing div encompassing individual posts and not the entirety of the first five.

    This is best illustrated by the “date” category where I wan t the first five to display inline (although I used div floats instead of inline lists) and the ones after 6 to appear in a list format. I can’t figure out where to put the <ul>.

    Is there a way to put the pagenum outside the loop?

    Links: Default category page
    Date category page

Viewing 4 replies - 1 through 4 (of 4 total)
  • Is there a way to put the pagenum outside the loop?

    I need some clarification on that question. When you say “pagenum” do you mean like when posts are paged?

    If thats the case, yes you can grab that from outside the loop, as that’s not related to the loop.

    <?php echo $paged; ?> will get you the pagenumber

    If you want to manipulate stuff based on the pagenum, mess around with something like this:

    <?php if ( $paged < 6 ) : ?>
    blah blah blah my css or div thing here.
    <?php endif; ?>

    you can also do that using if/else statements

    <?php if ( $paged < 6 ) {
    blah blah blah
    <?php } else {
    blah blah blah
    <?php } ?>;
    Thread Starter JaneLitte

    (@janelitte)

    I’m not explaining myself very well. The “while” command starts the loop and any styling within the “while” command affects each post individually. I want to be able to style the first five, as a set, differently from the remaining ones .

    I.e.,

    <div id=”featuredid”>
    post 1
    post 2
    post 3
    post 4
    post 5
    </div>

    <div id=”normalappearance”>
    rest of posts
    </div>

    I guess I need two loops, one that runs from posts 1-5 and another loop that runs from posts 6-whatever.

    Is that possible?

    Definitely, Jane, it’s the standard approach with this issue. Check out Multiple Loops… though their writeup makes it sound pretty hairy. Essentially you’d be using query_posts.

    Thread Starter JaneLitte

    (@janelitte)

    I have to apologize. I didn’t really conceptually understand what I was trying to do and that was causing me many problems.

    However, the answer to the question I posed is this:

    <?php
    $posts = query_posts($query_string .

    '&showposts=5');
    ?>
    `<?php while (have_posts()) : the_post(); ?>
    <?php include(TEMPLATEPATH . '/cat.php'); ?>
    <?php endwhile; ?>

    <div class="clear"></div>
    <?php rewind_posts(); ?>
    `<?php
    $posts = query_posts($query_string .'&offset=5');
    ?>
    <?php while (have_posts()) : the_post(); ?>
    <? include("normalloop.php"); ?>
    <?php endwhile; ?>

    Now, what I am trying to do is display the second query fully but in alphabetical order by post title.

    Edited to add:

    I added “orderby=title&order=asc” to my second query and it’s all perfect. Sigh. The wordpress forums are a great resource. I just need to use them better. Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘postnum, css and loop dilemna’ is closed to new replies.