WordPress.org

Ready to get started?Download WordPress

Forums

Best way to have two loops? (7 posts)

  1. Saracen
    Member
    Posted 8 years ago #

    There doesn't seem to be consunsus on how mest to have two passes of the loop. There are a couple of suggestions I have read.

    What I require, is to have the first 5 posts in full (up to the more), then the next 10 with just their titles.

    How is the best way to do this?

  2. kashou
    Member
    Posted 8 years ago #

    You actually only need one loop to do this. Just add a counter right after the loop starts and an if/else statement. If the counter is <=5, then the_content....else, the_excerpt.

  3. fox_ahmed
    Member
    Posted 8 years ago #

    السلام على من اتبع الهدى
    اما بعد ?قد وردنا انكم قمت بالسب ?ى الاسلام والمسليمين
    ونحن سو? نقاطع منتجاتكم ايها الاعداء اعداء الاسلام انالله سو? ينصرنا عليكم ايها الحقيرون ابناع العاهرات حتى لو وصل الموضوع لاراقة الدماء امضاء

  4. obharath
    Member
    Posted 8 years ago #

    hi saracen, i am also looking for the same code as u asked . can u post that code for the loop pls. the first 5 posts in full and next 5 just titles.

  5. Saracen
    Member
    Posted 8 years ago #

    How about if I require the two sections to be in different parts of the page with different CSS applied?

  6. petit
    Member
    Posted 8 years ago #

    Then you should wrap them in different xhtml blocks, say <div>´and give them different classes <div class="first5">´ ´<div class="therest">´ and then figure out a way of placing the blocks with CSS.

    Admittedly tricky, because the blocks must come in the correct sequence in the document flow.

    Only if you do absolute positioning, can you place the two blocks whereverever you want. But then you as for trouble.

  7. leflo
    Member
    Posted 8 years ago #

    You also could use rewind_posts and query_posts. I did this for the Musil theme.

    If you look at the home page for example, you'll see four WordPress loops working (one for the featured post, one for the sidenotes, one for recent posts and one for the rest of the posts).

    Be aware, that you might have to save and restore some internal WordPress variables to get it all working correctly. Peek at my source for examples. :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags