You’re 95% of the way there already. Just add if ( $my_query->have_posts() )
and incorporate your $odd
variable:
<?php
$my_query = new WP_Query('offset=5&showposts=10');
if ( $my_query->have_posts() ) :
$odd = false;
while ($my_query->have_posts()) : $my_query->the_post();
$odd = !$odd;
?>
<div class="<?php if ($odd) echo 'uneven '; ?>post">
<h3><a href="https://wordpress.stackexchange.com/questions/70713/<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
</div>
<?php
endwhile;
endif;
Related Posts:
- Some doubts about how the main query and the custom query works in this custom theme?
- WP_Query vs get_posts
- Order posts by ID in the given order
- Get the number of posts from the current page results
- WordPress Custom Query to show posts from last x years
- Query Custom Meta Value with Increment
- How to query ‘posts_per_page’ to display a different blog posts index template?
- Exclude first 5 posts of specific categories in the main loop
- 2 loops on page – one with orderby rand second orderby date
- Query posts by specific word on title
- How to use offset in WP_Query
- Five posts from a category in footer
- Multiple loops without repeating content
- WP_Query condition affects posts_per_page count
- Some doubts about how the main query and the custom query works in this custom theme?
- Include current post into loop
- How to provide meta_key array to wp_query?
- get_posts output always same post
- How to create custom query by keyword in post title?
- WP_Query – Adding “offset” posts to the end of the loop
- Stomping WP_Query in author archive to facilitate pagination with custom queries
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Conditional operator OR not working with custom fields
- Get posts that do not have the same tags as current
- Should I reset $wp_query?
- AJAX Breaking Offset Argument In WP Query
- 2 queries with counters
- Offset WP_Query by negative 1
- Paginate pages with dynamic query
- Performance concerns: index.php vs taxonomy-$taxonomy.php
- Determine if ID is page or post and query the ID
- Custom template for password protected page
- Magazine style frontpage with multiple categories/loops and no duplicate posts
- Duplice post with standard WP loop – fixed by using query_posts() instead
- How do I stop the same post showing multiple times in a archive?
- Custom query for custom post type not getting correct post ID
- Problem with my loops
- WordPress For Loop Prints Unwanted Extra Paragraph Element
- How to order posts, that have already been filtered by custom taxonomy, by their category names?
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- query_posts() doesn’t seem to be called in my page
- Some doubts about how the main query and the custom query works in this custom theme?
- Ordering Posts by parent category, name ascending
- Converting an existing query_posts to WP_Query
- Multiple loop for “featured” items returns wrong posts
- Show number of posts AND number on current page (cannot make it work)
- Can I force WP_Query to return no results?
- WP_Query and next_posts_link
- Using OR conditions in meta_query for query_posts argument
- Get array of posts from the current archive page loop
- Get posts by menu ID
- How can I save an array from a random post sequence for later use?
- Meta Query with date and time on the same Day before given time
- In loop: posts have thumbnail AND other variables
- How to order category.php loop by ‘meta_value’?
- Add inline HTML to posts published within last 24hrs
- Move posts to top of WP_Query if in certain Taxonomy?
- Display different number of posts from one category on the different pages
- Pagination not working Search posts
- Can certain (site-crashing) limitations on WP_Query in shortcode be overcome?
- Implementing an OR statement to wordpress wp_query
- Get List of all the Authors
- How would I get 1 latest post from a query for 5 posts?
- WP_Query loop within WP_Query loop
- Refine search results using WP_Query
- How to show subcategories using loop?
- Query with a meta value inside a given range
- Show Sticky Post at the top but do not show again in the loop?
- Any number in meta key (wp query)
- Out Of memory issue on post per page parameter
- Check if loop has any categories?
- WordPress query with items from more than one selfdefined taxonomy as `term` argument
- How to display an other custom post type in a different custom post type’s archive?
- Change query from cat id to slug or name?
- Using Wp_Query without the loop?
- Issue with front page navigation after upgrading to 3.4
- Easy way to write complex queries in wordpress
- Exclude recently updated post from custom WP_Query using multiple loops
- How to use WP_Query() on single.php?
- difference between querying database and using the loop
- Loop increase in while loop not working
- Continue or break the while loop
- Loop posts based on permalink term
- WP_Query offset is returning post from prevois loop
- WP_Query: Show 10 posts in date order, first three random
- Does putting queries within loops cause an issue on WordPress?
- Get next/prev image/attachment in time with date query
- Custom Post Type Query W/Category Dropdown
- Optimising WP_Query with ACF Fields
- Filter products on category AND tag
- how to get custom attachment url?
- WP_Query & Duplicate entries
- Calling a function with WP_Query only ever brings the first result
- Create multiple sections for all categories and then queries all the posts for each of those categories
- Optimising specific Query with ACF meta objects
- query_posts with sorting on a custom datestamp
- Next / previous posts link doesn’t show up with Posts 2 Posts
- Query Posts by date range with fixed beginning and end
- How to exclude certain portfolios from a loop
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise