I haven’t tested this, but it looks like you just need to set an iteration variable (usually abbreviated $i
), like this:
<?php
$i = 0; // This sets your variable
$query = [
'post_type' => 'post',
'posts_per_page' => 5
];
$query = new WP_Query($query);
while ($query->have_posts()) : {
$query->the_post();
if($i == 0) :
get_template_part('loops/acc-cards');
else() :
get_template_part('loops/cards');
}
$i++ // This iterates the iteration variable $i
wp_reset_postdata();
?>
Related Posts:
- WordPress query undefined offset in loop
- Problems With Query and/or Template Part and/or PHP
- Query multiple custom post types in single loop
- Inject post (from specific category) between posts in Loop
- Alter query on edit.php
- How to loop over custom fields in a page template?
- Specific Loop For 2 Within Each
- Easiest way to show total number of subpages
- Use template for posts with a particular category grandparent
- spliting posts into two columns
- How to get to a specific position in wp_query?
- Custom excerpt function re-factoring
- Automatically add custom CSS to new posts using a category template
- How can I add extra word in permalink when someone click download button?
- Increase offset while looping
- remove post that has no content
- How to add div blocks after certain set of post
- How to avoid duplicates when creating recent network posts
- How to overwrite orderby with add_query_var
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- Why is a wp function used in current PHP namespace’s callback not resolved to global scope?
- Issue with custom loop in Archive page
- Only show first image in foreach loop
- How can I get “Previous” and “Next” to show in the navigation besides the links?
- Do not duplicate posts with multiple categories in multiple loops
- Unable to render custom field after attempt to generate a list of recent post in page template
- Limit tags shown in post
- How to pick “full/thumbnail” images in the loop?
- Echo array value
- Wp Query : Order by distance lat,lon
- Advanced Query posts
- Build A Custom SQL Query for WordPress Search
- My Custom Post Type AJAX Query is Returning no posts – why?
- WordPress Custom Form – Getting Query Vars, Weird Glitch?
- Check if current post in loop is last on current page
- Is there anyway I can call the year once?
- How to display last whole post on the homepage
- How do if all posts has this category ID then do this
- Let user select the number of posts shown per page jquery error
- Get current_post in reverse order with pagination
- Pagination in WP Queries
- Add div after every 4 posts then every 2 posts for a responsive loop
- Insert div after every three posts in home.php [duplicate]
- Get posts associated with media attachment
- Loop returns more items than exist?
- Automatically create a loop for post ID
- why is this content-template not showing any of my blog-entries?
- Excerpt all post content Content Same Size without word cutting off
- Loop on a wordpress Page instead of content coming from the WP text editor
- How to create a loop that will display one post and stop?
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- Count the number of matching post names in foreach loop
- Need Help With Making Full-Width Template for Blog Posts (common methods aren’t working)
- Issues applying JSON body filters in EU F&T Portal SEARCH API with WordPress integration
- Can I make get_users() query global?
- Find Site ID From WP_Post
- WP_Query: getting posts where custom field exists
- How to pass a variable to get_template_part that’s updated every time the template part is called?
- What’s a good way to allow overwriting files within a child theme if I want the same folder structure?
- How to unlink all posts from tracking same amount of views
- How to display SQL query that ran in WC_Order_Query?
- Array to string conversion on array_map
- Store metakey value as an array
- Increment paged on WP_Query
- Custom Post type slider with thumbnail navigation
- Why my loop isn’t working? [closed]
- how to display this functions?
- is_page_template showing partial results
- WordPress loop by meta key that is an array? and how loop multiple arrays
- Adding regular php file to site
- use loop to return blog details
- Advice on creating a WP Archive Template with Custom Taxonomy (get_term_meta)
- Parse error: syntax error, unexpected ‘}’ [closed]
- add_filter function concatenate string and locate_template function
- How to get current post category details inside “loop”?
- How to render a block from php template
- Shortcode to pull posts
- Template Loop – add switch case php
- How to pass current loop data into nested loop
- How to use mysql LIKE with wpdb?
- Get all posts as an array ID => Name
- PHP -> SQL Query with Summing
- How to hide posts of a specific custom category in WordPress?
- Reading settings in the home page precisely home.php
- How to get post ID from button and pass title to Modal
- Override Admin menu icon
- Do I need to edit my theme in order to change the title of my blog page?
- WP Query Leads to 502 Bad Gateway (Timeout Because Query Takes Too Long)
- Add new post in existing categories using wp_insert_post
- Post repeated when opening in overlay, how do I solve this? [closed]
- home.php show blog posts as grid view
- WordPress upload file size error even after raising php limits
- How do I add more options to the post-new.php page?
- Problem with custom loop and wp_list_pluck [closed]
- WP_Query multiple post results
- Convert Featured products loop into Recent products loop?
- get post id from wp_insert_post for get_template_part
- How to suppress template-parts in undescores?
- Wpdb get->results to out the the month from the db
- How to add post meta in while loop?