• Resolved prempwp

    (@prempwp)


    Okay, i want to display 3 posts from a particular post type and these three posts will be A SINGLE LIST ITEM and then i want to repeat another 3 set of posts in another list item, within an un ordered list.

    Please tell me how i can do that.

    Example:

    <unordered list>
    
        <li first>
             <item 1>
             <item 2>
             <item 3>
        <li second>
             <item 1>
             <item 2>
             .... (so on)
    
    </unordered list>

    For extra info. I am trying to do this because i have a slider in which i want to display 3 thumbnails at once, and when user clicks on next button, it slides to show the next 3. So each set of 3 thumbnails will be a list item.

Viewing 4 replies - 1 through 4 (of 4 total)
  • one query – general structure:

    <ul>
    <?php while(have_posts()): the_post();
    if( $wp_query->current_post%3 == 0) echo "\n".'<li>';
    $item_nr = ($wp_query->current_post%3+1);
    /*output code here*/
    if( $wp_query->current_post%3 == 2 || $wp_query->current_post == $wp_query->post_count-1 ) echo '</li>';
    endwhile; ?>
    </ul>
    Thread Starter prempwp

    (@prempwp)

    @alchymyth, Thanks for your help, i tried that code.

    The only thing is, with that code it won’t add the
    <li> to the first post, so i modified it to this:

    <?php $postCount = 1; ?>
    <?php if(have_posts()) : while(have_posts()) : the_post(); $postCount++; ?>
    <?php if( $wp_query->current_post%3 == 0 || $postCount == 1) echo "\n".'<li>';
    $item_nr = ($wp_query->current_post%3+1);	?>
    /*all the code here*/
    <?php if( $wp_query->current_post%3 == 2 || $wp_query->current_post == $wp_query->post_count-1 ) echo '</li>'; endwhile; endif; ?>
    </ul>

    But, now it doesn’t display anything at all. in short, this code doesn’t work.

    Thread Starter prempwp

    (@prempwp)

    OMG this is fantastic: @alchymyth you, sir, freed me from my 3 days struggle. It all works now, it was just a minor CSS problem.

    Thank you very much @alchymyth and @esmi as well.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Displaying posts (tricky)’ is closed to new replies.