Title: Displaying posts (tricky)
Last modified: August 20, 2016

---

# Displaying posts (tricky)

 *  Resolved [prempwp](https://wordpress.org/support/users/prempwp/)
 * (@prempwp)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/displaying-posts-tricky/)
 * 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)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/displaying-posts-tricky/#post-2667649)
 * You will need to start looking at custom queries and [multiple Loops](http://codex.wordpress.org/The_Loop#Multiple_Loops).
   
   [http://codex.wordpress.org/Function_Reference/get_posts](http://codex.wordpress.org/Function_Reference/get_posts)
   [http://codex.wordpress.org/Function_Reference/WP_Query](http://codex.wordpress.org/Function_Reference/WP_Query)
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/displaying-posts-tricky/#post-2667682)
 * 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](https://wordpress.org/support/users/prempwp/)
 * (@prempwp)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/displaying-posts-tricky/#post-2667784)
 * [@alchymyth](https://wordpress.org/support/users/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](https://wordpress.org/support/users/prempwp/)
 * (@prempwp)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/displaying-posts-tricky/#post-2667788)
 * OMG this is fantastic: [@alchymyth](https://wordpress.org/support/users/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](https://wordpress.org/support/users/alchymyth/)
   and [@esmi](https://wordpress.org/support/users/esmi/) as well.

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

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [prempwp](https://wordpress.org/support/users/prempwp/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/displaying-posts-tricky/#post-2667788)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
