That’s a pretty complicated approach you’re taking. Why not simply add a counter? Like this:
$i=1;
echo '<div class="row full">';
if( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
if ($i < 3)
$class = "large-6 medium-6 small-12 columns"
else
"large-4 medium-4 small-12 columns";
echo '<div class="' . $class . '">'
... output your post ...
echo '</div>'
if ($i=2) echo '</div><div class="row full">';
$i = $i+1;
}
}
echo '</div>';
Related Posts:
- WP_Query for WooCommerce Products
- How can I display recent posts from a particular category in my header?
- Using AJAX to return search form results
- Pagination is not working using WP_Query
- Two queries on the same page with pagination
- Why is this coming back as null? Thats wrong. There is one post
- How to display future posts – modified query still yields 404
- WP_Query arguments to fetch custom post type posts which are in certain category?
- Which method is faster to get a single post?
- Import wp users via one click demo option
- How can I use $wp_query->tax_query as tax_query parameter for a new WP_Query instatiation?
- Adding column to wp_posts table or join wp_posts table with another table
- Two loops on archive page
- Check if loop has any categories?
- How to make search for posts using get method?
- Multiple filter conditions for WP_Query
- Reset WordPress Post Query to default
- What happens to the default query when I use WP_Query?
- How to Create a Random List of Child Pages
- Wp_query with 2 meta keys and array of meta values
- Problem with get_page_by_path() using with WP_Query
- WP_QUERY wrong ammount of posts
- WP_Query to get post on frontpage
- How to create Page templates for showing Blog posts in different layouts?
- Writing less unnecessary code with WordPress
- How to separate two columns from one content on a page template?
- Using Ajax and WP_Query to load more posts on category page fails
- WooCommerce | AJAX | Product Pagination | Help me implement Ajax Pagination
- Custom WordPress post query for displaying time-released content on website
- How to display author meta and count numbers for each user in comment.php?
- Displaying Pages in Nav Sub-Menu with Specific Taxonomy Terms?
- Global page ID variable empty error
- Get posts by similar names and categories
- Second WP_Query loop shows data from main query
- active link for most recent post on vertical tabs
- Custom Theme Building & Permalinks
- WP_Query issues with argument posts_per_page
- Get author meta data with no published posts in author.php?
- How to display posts from a specific term first then another posts from another terms using tax_query
- Why ignore_sticky_posts argument is in sticky post query?
- Find out total number of pages in global query on archive page?
- Resetting post data to previous loop in nested loops
- Is it possible to completely stop WP_Query retrieving posts?
- Make loop display posts by alphabetical order
- Displaying several specific pages using WP_Query()
- WP-CLI How to generate a list of posts with corresponding meta values
- Query to return maximum of one post per author
- Get attachment by slug
- Warning: urlencode() expects parameter 1 to be string, array given
- Group posts by custom field
- How to get the posts published in last two days using WP_Query?
- getting posts and number by specific meta value in multiple meta
- Get attached media only
- Can not switch the queried post in pre_get_posts hook
- how to fire join query with post_meta
- Minimising number of queries on a page when using Advanced Custom Fields
- How to find exact match for search term in WP_Query? What is the additional string added in LIKE query in WP_Query?
- Improve wp query perfomance on large db
- If two first numbers exist in wp_meta_query value
- How to query for posts without a post_format
- get_posts – find out if querystring was crap and fallback is used
- Function get_queried_object() return NULL in custom taxonomy
- Search pages that are a child of the current page
- Change query_posts to WP_Query in page but does not work
- Modify WP Query post__in before have_posts()
- WordPress search posts by author name with autocomplete
- WP Query using tax_query & meta_query
- How to control a common terms list from one place?
- Exclude Category filter from Portfolio section
- Search form not working with custom query?
- Is there something wrong w/ this code?
- Query Vars Not Set in Main Query
- ACF Query Structure
- Order post type by sum of two custom fields
- Order WP_Query results by meta key value in custom query
- Need help understanding this WP Query [closed]
- Ordering posts by custom field and grouped by month
- How to get main menu only with wp_nav_menu
- Ajax (jquery) wp_query pagination returns -1
- Query to get result by Title or Meta along with tax_query parameter
- Why are my wp_query args being ignored if post_type = CPT
- Woocommerce Get Orders By Meta Value
- How to search through all child taxonomies using WP_Query?
- WordPress Query optimaization for slow query
- WordPress – just refresh blog archive by new query
- how to move a page from one drop down menu to another drop down menu
- How to pass a php variable to js within a template?
- Meta query doesn’t remove placeholder escape before query
- Multiple values in WP_Query : category__and
- Get all wp_users sort by metakey
- How to use wp_query in different column in single loop
- Paginated Post List on Front Page
- Show subscriber id in loop
- modifying the loop multiple times with arguments passed through ajax to wp_query
- Website goes slow down after importing long database
- How to Query Updated Post in WordPress
- wordpress nested loop
- Query posts only shows 1
- First post outside of loop, homepage only?
- WP Query returning all posts when Meta_query is null