query_posts
should only be used for the main loop. Instead, use a new instance of the WP_Query
class:
$my_query = new WP_Query( array(
'post_type' => 'post',
'posts_per_page' => 10,
'order' => 'DESC',
'paged'=> $paged
) );
echo '<ul>';
while ( $my_query->have_posts() ) : $my_query->the_post();
if ( $my_query->current_post > 0 && ( $my_query->current_post + 1 ) % 6 == 0 ) {
echo "<li>I'm odd one</li>";
} else {
echo "<li>" . get_the_title() . "</li>";
}
endwhile;
echo '</ul>';
The above will “do the special thing” every sixth element. Should you just want it on the sixth itself, use $my_query->current_post == 5
instead (index starts at 0).
Related Posts:
- How to exclude latest x posts from a paginated query?
- Query posts distinct authors
- How to get previous 10 days post from a specific date – WP Query
- Hiding posts in a list from specified categories
- How would I get 1 latest post from a query for 5 posts?
- Exclude posts with empty post_content in wp_query
- Improving WP_Query for performance when random posts are ordered
- Reset Popular post query?
- Why WP_Query(‘showposts=5’) shows only 1 post?
- is there a way to show the the post title after the image?
- Blog post per page setting conflicting with custom WP_Query?
- How to exclude latest x posts from a paginated query?
- Random ajax load only works with posts_per_page set to -1
- posts_per_page option limits the number of Gallery items
- wp_posts table: safely remove unused columns to save database storage
- Query Posts by Custom Field
- Nested WP_Query breaking loop
- WordPress query_posts by tag doesn’t work anymore(?)
- why the same code got different results when using query_posts in functions.php and index.php
- Query for first 3 posts to change the look and feel
- How to get posts published on the latest date?
- How to check in functions.php if there is data in a WP_Query?
- Shortcode with ‘year’ parameter
- On what hook can I get the queried object’s final state?
- wp_query with ajax
- How to give classname to post if post has no content?
- WP_Query: Show 10 posts in date order, first three random
- Random posts that always include a particular post?
- WordPress post filter menu
- Query function not executed between element [closed]
- Echo the number of posts being displayed
- WordPress query portfolio posts
- Display 3 posts with different HTML markup using a loop
- Show posts from two specific category in WP_Query
- How to create loop of posts except post ID defined via ACF field
- Displaying all posts from other sites on the network on one site
- Multisite how to display merged posts from two sites and sort by latest date?
- Show 5 posts and than 3 posts offset with pagination
- wp_query args with relation
- Manipulate query to show specific post
- Sort / Filter Queries
- Why I obtain this WP_Query strange behavior trying to select posts having a specific tag?
- Why I have this strange behavior when I try to exlude the featured post from posts visualization?
- How do I control the fallback query after the original query returned cero posts?
- Remove duplicated posts in the loop if post has more than one category
- Adding a category at even positions on main loop with modified pagination
- wp_query select if have comments
- query_posts different amount of posts per page [duplicate]
- Skipping first 3 posts in wp query
- Accessing the post content with WP_Query
- Can’t show comments count per post outside loop
- How to output comments number of a post per day?
- If specific user role then sticky post
- Display posts with comments closed, with pagination?
- I want to query posts in monthly basis
- Custom WP_QUERY $args
- Limiting the number of posts in WP_Query leads to unexpected result
- Why is querying posts messing up my pages?
- WP Query – Posts Per Page not working in combination with category__in
- How to do set post permalinks using 6 digit random unique function?
- Multi row post list
- Get posts with multiple categories
- Do not show children of a category
- unique post in “$args” of wp_query display more than one post
- Display current post position in Elementor Posts widget
- Custom wp-query in wordpress rest api
- posts_per_page returning only one post
- Need to know custom code to display random and most viewed posts in wordpress posts and pages
- How to retrieve certain number of images from a wordpress post?
- WP_Query custom field pass the post id
- Current and next month posts
- Same post appears in related Posts?
- How to assign a post to a post parrent?
- get parent fields title, content excerpt etc
- AWS usage queries
- How to show multiple posts thumbnail, title and date in widget
- Group first, 2nd, 3rd, etc posts by category terms
- Manipulated offset and pagination, can’t display last post anymore
- How to fetch courses in all languages in WordPress?
- How to display particular set of wordpress post on a webpage?
- How can I use query_posts to loop through posts and construct my own content?
- Assign a day of the week to post, e.g: Assign Monday to post and have it only appear when the day is Monday
- Change archive results based on GET request
- Querying posts from current category, using a variable as array argument
- Wp_query loop is not working as it should
- Is it possible to query a category with specified posts?
- Is there a global page/post/product/anything ID?
- WordPress loop uses unmodified posts array, why?
- Need help writing loop to display posts by categories in separate divs
- Modify WordPress loop after it has been run
- Show posts between two Custom Fields date
- Query to get data of a post, if in category?
- Order posts by custom field
- Ordering posts alphabetically by meta keys and title
- Why I getting only 1 post?
- How to limit post query to only return a total count of items with certain post statuses?
- First post in loop displays twice
- How do I get content of custom post type through post ID
- Do I need to create a multisite for querying posts from multiple WordPress sites?
- Filters do not work when there are multiple (one works)