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)
- Should we trust the post globals?
- Check if a menu is empty?
- WordPress Template Engine?
- Display only text to WordPress loop without loosing the text formatting
- Custom post type loops with different page templates
- How to display related posts from parent category
- get understrap pagination to work with custom query
- my function doesn’t return my post from today
- Way to display “Yesterday”, “Today”
- How to override wp-admin styling
- multiple if statements [closed]
- Multiple choice in a custom taxonomy
- How does the ternary operator work in the wordpress loop post?
- Get stock by custom meta field on all Woocommerce variable products
- Loop through categories and display posts title under each dropdown
- How to store post ID’s in cookie or session to display the same posts later
- How to set variable, pass it to a partial file and remove it after?
- Can’t find infinite loop cause
- register_taxonomy() take much queries
- how to show only specific category for a template
- How to loop through all the attached images in a post, and get their url one by one
- single.php with different look by category
- Show recent posts starting at a specific number archive
- WP Query Leads to 502 Bad Gateway (Timeout Because Query Takes Too Long)
- home.php show blog posts as grid view
- Displaying content on posts page based on category
- how to make an array of post id’s in is_single
- Loading Posts & Category with Ajax
- How to get thumbnail with pure PHP in a WordPress database?
- WordPress call post-ID in jquery
- List all anchor links on a page
- How can I modify this code to make the search box include tags and meta
- understand what code is doing when prepending /blog
- My worpress search page is showing no results
- How to display 8 posts in four columns and 2 rows on a carousel slide?
- Display metabox galleries on specific page template in admin editor
- Inside Array – “unidentified index” error with “prepare was called incorrectly” despite not calling the prepared statement with wordpress [closed]
- Having trouble with customizing blog posts on the home page
- If is_page elseif is_page not working like I want it to
- View tag description on page
- Query doesn’t display text data with apostrophes
- Display product attributes for current product
- Dynamically Create Posts Via XML File
- Display the latest post from some selected authors
- How can I put a custom field as the link of a button shortcode?
- Transient Loop Not working as expected
- is there away to hide php code in wordpress not to show in PAGES