One way to output the same query yet style it differently is to use current_post
or in combination with rewind_posts
, or using rewind_posts
alone.
So for example:
Your initial query
if ($my_query->have_posts()) :while ($my_query->have_posts()) : $my_query->the_post();
$counter_id = $my_query->current_post + 1; //this is the counter
// then use a conditional to style each on based on `# or %
if ($wp_query->current_post % 2 == 0)
// add custom styles
endwhile; else:
//
// Or rewind the post with a count and conditional
rewind_posts(); //rewind the post back to the start
if $counter_id == 1 //do some style
if $counter_id > 3 // do some style
//etc
Another more simple option is to just use multiple separate loops (and DB query’s)
I hope this logic makes sense and helps , I don’t have the time to actually write your query and test it.
Related Posts:
- How to customize categories panel?
- Two columns in homepage each with one category
- Split multiple categories into two columns
- Is There a Difference Between Taxonomies and Categories?
- Only one category per post
- Get rid of WordPress category, tag and author archives?
- Filtering categories in the permalink structure
- get_categories hierarchical order like wp_list_categories – with name, slug & link to edit cat
- wp_nav_menu not appearing for a couple pages
- Why aren’t sub-categories nested after creating post in the WP Admin?
- Preventing index.php?category_name=something from redirecting
- How to get category id of current post?
- Programmatically create product category and add thumbnail in woocommerce
- Trash bin for categories
- Categories’ hierarchy in URL
- Display one category in one page
- How to get next previous category in same taxonomy?
- Exporting just posts of a specific category
- How to display only the parent category in the permalink
- How to add HTML5 ‘required’ attribute to wp_dropdown_categories() without JavaScripts?
- How to get category id in single.php wordpress?
- If a post has two categories with different permissions, what will happen? [closed]
- Dropdown category filter
- Filter out posts before display category count
- How to show in search results posts with a particular tag in a particular category?
- Category vs Tag vs Table
- How to find the number of Tags a post has?
- Multiple menu items highlighted
- Add title, post content, and category like add_post_meta and update_post_meta
- wordpress wp_list_categories
- How to create button to direct to certain category
- Group listed elements by category
- Highlight wp_nav_menu when category is selected
- Get link which associated with a specific category and tag
- How to disable default category linkbuilding?
- How to assign posts without any category to the default category
- Show only first category name in RSS?
- Show parent category in URL of subcategory archive page
- Filter $cpt categories to omit certain category
- Yearly Archive for Categories with dropdown
- get_categories listing foreach with children
- Removing subcategories from permalinks [duplicate]
- How to query categories with Advanced Custom Fields?
- Undefined property: stdClass::$id when retriving term ID
- Wacky taxonomy in wordpress
- Link to the next/prev posts in index loop in same category?
- Output the text before category
- Change div background acording to the selected category
- get_the_categories() but exclude children of “Uncategorized”
- How to exclude a particular category from the category list
- Why title_li =” not working
- Custom Permalink with child categories creating 404
- Cannot filter categories by parent category
- Redirect year month day postname permalink structure to category postname structure
- Show all sub categories?
- Category nicename inside loop in wordpress
- Exclude all subcategories in the_category (post)
- Displaying another main nav menu for specific category
- Exclude categories from list (wp_list_categories)
- How to display the 5 latest post titles but allow only 1 in there of a specific category
- WordPress: Using the category slug get the category ID using mysql query
- Create a Category with a front-end post
- Posts made to category don’t show up (do show up on frontpage)
- Exclude category to “the_breadcrumb” functions
- wp_dropdown_categories() works correctly but the list is not filtered in admin for custom post type. What is the problem?
- Migrate the posts of a category to another blog as a custom taxonomy
- Woocommerce only display child category when parent is checked (on add new product page)
- Add $args to wp_list_categories
- How to hide a category or tag everywhere EXCEPT for use with get_posts
- Show parent category wp_list_categories wordpress
- Taxonomy custom check box meta field not getting saved
- Subcategories randomly not working after page/post/category edit in wordpress. Fix: saving permalinks twice
- In if…else condition, the else statement shows even if if statement is correct
- Restrict retrieved terms by category?
- Get category from slug list
- Re-coding category-template.php to go to custom URL
- Category removal – Portfolio Category:
- How to Change Sort Order of default WordPress Catgory Widgets?
- Custom filters inside a specific category?
- $args Orderby The number
- Most efficient way to have 1 template for parent, 1 template for child categories?
- Function to list posts from current post’s category fails in WP 3.8
- Multiple parent categories
- Custom fields setup when category selected filter subcategories
- How to use Greek characters/letters in a query?
- Make three menus with three category levels
- Getting categories to change appropriately when using $cat = ‘ ‘;
- how to call the category of the post
- Category related -> excerpt, title and thumb in sidebar on article page
- How to have a category not show up in query post with page panigation?
- single category widget with conditional terms
- Remove the current item from a menu
- why is the delete option missing from just one category?
- Get all categories
- Show category post order ASC
- How to display all category images for single post in a page?
- Use same wordpress category base and tags as the prefix as the post permalink
- Adding category to existing post (uploaded file)
- how to create a page that shows all of multiple category posts on a single page
- Quick Edit on taxonomy names results in error