Your $count++ needs to be after your endif statement. It’s not counting up because your counter is always at 0 which means you’re always in your “if” portion of your statement not your “else”.
Like this:
$args = array(
'post_type' => 'post',
'post_per_page' => 3,
);
<?php $loop = new WP_Query($args);
$count = 0;
while ($loop->have_posts()) : $loop->the_post();
if ($count == 0):
?>
<!-- last post -->
<div class="post-one">
<h1><?php the_title();?></h1>
</div>
<?php else:?>
<!-- second et third post -->
<div class="post-two">
<h2><?php the_title();?></h2>
<?php the_excerpt();?>
</div>
<?php
endif;
$count ++;
endwhile;
wp_reset_postdata();?>
Related Posts:
- Get first post from wp_query
- Accessing the post content with WP_Query
- How to query serialized array by comparing greater than (>=)?
- Query posts distinct authors
- How to get previous 10 days post from a specific date – WP Query
- Specific loop in Shortcode
- Sort posts by activity date
- prevent showing posts of an specific category in admin posts section
- How to output comments number of a post per day?
- Search widget breaks when using multiple loops?
- How to change bulk post status
- Should ‘setup_postdata()’ be reset with ‘wp_reset_postdata()’?
- If specific user role then sticky post
- Display posts with comments closed, with pagination?
- WP Query related posts by current page Tag ID
- I want to query posts in monthly basis
- Custom WP_QUERY $args
- Improving WP_Query for performance when random posts are ordered
- WP_Query get posts from custom posts by category
- Accessing post->ID outside of the loop for listing child pages
- Limiting the number of posts in WP_Query leads to unexpected result
- List posts in a given category
- Reset Popular post query?
- Query Posts multiple conditions
- Future post ID not showing
- Search by post title and content in wp_query without order
- How to insert 2 args into 1 Wp_Query for a slideshow
- How to do set post permalinks using 6 digit random unique function?
- How safe is renovating $wp_query when doing WP_Query pagination in Page Template
- wp_query random post
- wp_posts table: safely remove unused columns to save database storage
- Using wp_list_pages() after calling query_posts()
- how to get post order by post id wp_query?
- Possible to alternate between two loops
- How to display all posts divided/ordered by post date? [closed]
- Why are my paginated posts always returning the same results?
- Is it possible to use WP_Query to only pull posts with attachments?
- Inner join overrides Advanced Custom Fields plugin’s get_field [closed]
- Every second post different class in blog view
- Display posts of specific category term
- Query posts by Author and/or by Tag
- Archive template combined with post slider and regular posts
- Can’t understand why sometimes a [caption] field appears
- Why in my query is display two title?
- Migrate posts from category and sub-category via SQL
- wp_query with ajax
- How to give classname to post if post has no content?
- Exclude some posts from displaying in wp_query based on some condition
- posts_per_page returning only one post
- How to convert query sql to shortcode in wordpress?
- Use posts_where to exclude posts ids from wp_query
- Why does WordPress search returns same number of results for every search query?
- Sidebar limiting to 10 posts?
- WP_Query get posts in custom database table [duplicate]
- WP query taxonomy optimization
- Override WordPress core post-template.php block template
- how to show comments only author which send own posts in wordpress
- Change Old WordPress Post Date Year
- Displaying all posts from other sites on the network on one site
- Display/Filter post using if else statement
- How to sort WP_Post Object array by object field in php?
- Search results for ACF data
- Multisite how to display merged posts from two sites and sort by latest date?
- Query prints posts without specific categories
- Numbered Pagination Showing The Same Posts After Altering WP_Query
- How to create page with post content in it?
- Using a meta_value or postdate to to query and orderby
- Exclude posts in home slider from sections
- Ajaxify Post Sort
- Override wp_link_pages pagebreak with filter
- Loop through all posts showing duplicates
- Manipulate query to show specific post
- Get current user, change users post status to published
- WordPress text field in array problem
- Random order of the 5 most popular posts
- My custom query is displaying random posts in random order
- Get query result according to merged array
- Blog only showing one post even though more published
- Display WordPress Post By Date
- GUID to related post not in current language
- Sort / Filter Queries
- How can I display a specific number of post in a category via a url
- Advanced Post Display/Pagination/Ordering
- How to show the posts list into a static page? Problems to use the loop into a static page
- How to Add Wrapper to Infinite Scroll Javascript?
- Order posts by separate menu order for different sub-categories
- Displaying Results From Custom Taxonomy Query
- Make assigning post to a specific category equivalent to assigning it to all categories
- Multiple loops on a Search result page?
- WP_Query retrieve custom posts but not the post showing
- WP_Query: Fetch posts that are in (category1 and not in category2), OR posts that are not in cagegory1
- WP_Query based on a custom field result
- Exclude sub sub categories from displaying in the archive page
- How do I show the post title if an advanced custom field hasn’t been used?
- WP_query sort by custom meta_key “price”
- How add class the_content();?
- Add custom PHP (no-SQL) filter to WP_query
- Filters do not work when there are multiple (one works)
- date_query returning only the most recent post instead of the post published before today
- How to speed up WP_Posts_List_Table __construct() Query on a wordpress website with over 1 million posts?