You can use $current_post
property of WP_Query
$query_args = array(
"posts_per_page" => "5"
);
$listedPosts = new WP_Query($query_args);
// the loop
if ( $listedPosts->have_posts() ) {
while ( $listedPosts->have_posts() ) {
$listedPosts->the_post();
if ( (int) $listedPosts->current_post === 0 ) {
// loop content for hero post
} else {
// loop content for remaining posts
}
}
}
Related Posts:
- How to exclude latest x posts from a paginated query?
- Why WP_Query(‘showposts=5’) shows only 1 post?
- Blog post per page setting conflicting with custom WP_Query?
- How to exclude latest x posts from a paginated query?
- How to get posts published on the latest date?
- WP_Query: Show 10 posts in date order, first three random
- Display 3 posts with different HTML markup using a loop
- Why I obtain this WP_Query strange behavior trying to select posts having a specific tag?
- Adding a category at even positions on main loop with modified pagination
- Should we trust the post globals?
- WP_Query: Why is sticky post not first item in loop?
- Query *only* sticky posts
- Display all posts from specific categories on a page
- How do I reorder (pop and push) items from WP_Query?
- Display content from a specific category
- Reverse chronology of post listing
- WordPress Number of Posts Not Changing With posts_per_page
- This AJAX Code Doesn’t Work – Looking for elegant solution
- Can’t show comments count per post outside loop
- How to Display Post View Count
- Hiding posts in a list from specified categories
- Converting multiple loops into one single loop with pagination
- Display posts with comments closed, with pagination?
- Group posts by year in loop
- Exclude posts with empty post_content in wp_query
- Loop through all product posts?
- Improving WP_Query for performance when random posts are ordered
- WP Query – duplicated posts once including tags in search results
- Reset Popular post query?
- Display post from current category and same tag?
- Inserting custom data to the_post() during loop
- How To Get Posts With A Specific Word
- is there a way to show the the post title after the image?
- Display all posts that were published before full post on single.php
- Two loops, one AJAX loop, exclude posts in first loop from second loop, loops are in different files
- WP Query – Posts Per Page not working in combination with category__in
- Pausing and Resuming WP_Query results
- Random ajax load only works with posts_per_page set to -1
- How to : pagination in 3 different custom loops on the same page
- List authors with the last post title and order by last post date
- wp_query random post
- wp_posts table: safely remove unused columns to save database storage
- Query Posts by Custom Field
- How to order posts in an arbitrary order?
- Display Posts on Custom Page
- Possible to alternate between two loops
- Wrong post title displayed from loop
- Nested WP_Query breaking loop
- WordPress query_posts by tag doesn’t work anymore(?)
- Get the amount of posts on a current page
- why the same code got different results when using query_posts in functions.php and index.php
- Query for first 3 posts to change the look and feel
- How to only publish posts with image in it
- Page and post loop same template
- Getting blog pagination to work on page set as front page
- How to check in functions.php if there is data in a WP_Query?
- Shortcode with ‘year’ parameter
- On what hook can I get the queried object’s final state?
- wp_query with ajax
- WordPress Loop: How to display recent posts in multiple divs
- Random posts that always include a particular post?
- How to display post list in a table layout (multiple queries in single loop)
- Not all posts showing in query
- how to handle the loop using filling bootstrap grid structure?
- Query function not executed between element [closed]
- Custom WP_Query not working correctly
- Echo the number of posts being displayed
- WordPress query portfolio posts
- Display specific posts on home page
- WP_Query of Category Not Showing First Post
- Change content off every sixth element
- While loop in functions.php outputting the_title() of each post on frontpage
- Show posts from two specific category in WP_Query
- How to create loop of posts except post ID defined via ACF field
- Displaying all posts from other sites on the network on one site
- Multisite how to display merged posts from two sites and sort by latest date?
- Display specific posts based on an ID of another post
- Numbered Pagination Showing The Same Posts After Altering WP_Query
- show loop id post , only first id can read
- Show 5 posts and than 3 posts offset with pagination
- Double loop output
- wp_query args with relation
- Loop through all posts showing duplicates
- Manipulate query to show specific post
- Wp_query loop is not working as it should
- Use special template for the first post in the loop
- WordPress loop uses unmodified posts array, why?
- Modify WordPress loop after it has been run
- show latest authors blog post
- Advanced Post Display/Pagination/Ordering
- Why I have this strange behavior when I try to exlude the featured post from posts visualization?
- How to show the posts list into a static page? Problems to use the loop into a static page
- Remove duplicated posts in the loop if post has more than one category
- Make assigning post to a specific category equivalent to assigning it to all categories
- How to inject a post within a loop
- wp_query select if have comments
- How do I show the post title if an advanced custom field hasn’t been used?
- First post in loop displays twice
- posts_per_page – Repeats only first posts ‘post__in’ array
- query_posts different amount of posts per page [duplicate]