• Resolved SimonJ

    (@simonj)


    Hi all!

    Ok, here is my quest :

    I would like to divide my loop on my category/index/archives templates.

    I would simply put a banner between the first posts and the folowing posts.


    ======================
    First post in the loop
    ======================

    [—BANNER—]

    ======================
    All the folowing posts
    ======================

    And I want to keep this schema over the pagination, ie when I browse the older posts in category/archive/etc.

    Normally, I would do so with :

    [1] A query posts with showposts=1 = Display only one posts.

    [2] The banner I want to display

    [3] A query posts with offset=1 = Display all folowing posts.

    But this method wont works with the pagination to browse older posts.

    I know how to get the pagination working with a single query_posts, with this code : $page = (get_query_var('paged')) ? get_query_var('paged') : 1;

    But it doesn’t seems to solve my actual problem with two loops…

    Am I clear enough? Anybody have an idea?

    Thanks!

    S.

Viewing 3 replies - 1 through 3 (of 3 total)
  • How about creating a simple counter in your loop?

    I’m no php expert, but something along these lines:

    $counter=1;
    $counter++;
    if $counter==1 {echo 'image.jpg'};

    I have no idea how that would work with pagination – does the variable get reset to 0 on each new page?

    Thread Starter SimonJ

    (@simonj)

    Sorry for the late feedback… I was out of town for holydays.

    I tried to play with your idea, the code you wrote above gaves me a good start for some google.

    Then, I found this article :

    http://imod.co.za/2009/04/09/wordpress-place-something-after-only-the-most-recent-post/

    The idea is to set the counter where you cass the “while have_posts” for the loop :

    <?php while (have_posts()) : the_post(); $counter++; ?>

    Then, call what you want anywhere before the “endwhile” with an “if” statement based on a counter value :

    <?php if ($counter == 2) : ?>
    <!--Do your stuff -->
    <?php endif ?>
    
    <?php endwhile; ?>

    Note the ($counter == 2) … Just change the number to adjust your need. In this example, you will display your stuff right after the second post…

    And it works with the pagination

    Voilà…

    S.

    wpcontentcom

    (@wpcontentcom)

    Hi SimonJ

    I posted a video tutorial on how to do this. http://www.wpcontent.com/post/190. I hope that helps!

    Eric

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Loop division and pagination’ is closed to new replies.