for a standard query, you can check the amount of posts with:
all posts for the query:
$wp_query->found_posts
and the posts on the page:
$wp_query->post_count
use that with a conditional statement to switch to the different layouts.
example:
<?php if ( have_posts() ) : //start of the loop//
if ( $wp_query->found_posts <= 4 ) { ?>
list output of posts
//this will need to include the 'while(have_posts())' including the 'endwhile' of the loop
<?php } else { ?>
float block output
//this will need to include the 'while(have_posts())' including the 'endwhile' of the loop
<?php }
endif; ?>
Related Posts:
- Problem with ‘post__not_in’
- Sort X categories by last update and show image
- using post__in allow duplicate post id
- Using dynamic conditions in ‘posts_where’ filter
- How to limit search to first letter of title?
- Counter code for paginated category pages in wordpress
- WordPress Search Filter Only for Page with Child of Child of Child of Child of Child
- pagination in author.php template returns 404 error
- How to modify the query to exclude posts by slug?
- Adding Variables to post query
- Tricky WP Query
- query_posts() ALWAYS displays something?
- Using ajax with paging and a custom sub-query
- Each post is showing twice in my custom query…?
- Exclude posts by post meta value
- How can I list posts with different formats depending on order?
- Can I use WP_Query one time and then filter the results multiple times
- How to solve this without flushing the rewrite rules for each post query the visitor triggers?
- How to check a list or feed of all posts under a category and tag?
- Best Query for blog posts
- Adding Category Argument into an Array for WordPress Query
- When should you use WP_Query vs query_posts() vs get_posts()?
- How can i get count from query post
- How to query for most viewed posts and show top 5
- Is there a way to exclude the content from the post variable to save on RAM usage?
- Display/query post formats
- How to query post by user role?
- Ensuring sticky posts are retrieved first (without using two queries)?
- Determine if more posts are available than was asked for in `query_posts()`?
- query_posts() in function makes global $wp_query out of sync?
- Perform query with meta_value date
- WordPress Custom Query
- advice on creating a ‘related posts’ query like the one used on stackexchange
- How to order posts by modified date without using ‘query_posts’?
- Help altering a query to exclude all but standard post format
- Post Title displaying but not in the wrapped HTML I need
- get_post_meta causes database queries
- Order post by year DESC and month ASC
- How to ensure that is_search() return false after query_posts
- Inserting Post Using wp_insert_post. How to Fill Yoast Plugin SEO Fields
- Retrieve or Query Pages by ID
- Query 1 taxonomy term, exclude another
- How to implement time filter to show random post 1 month for one category and 3 months for other categories
- Order by meta_key with two meta_queries
- Pagination on custom query
- Ordering terms before displaying posts
- What is the difference between “manage_{$post_type}_posts_columns” and “manage_edit-{$post_type}_columns”?
- Sort Posts by Multiple Meta Values [duplicate]
- Querying posts with meta value that begins with a certain pattern
- How to show only today’s post?
- Unable To Get Published posts using query_posts
- ACF Custom Field WP_Query, but need to get all posts, if field doesn’t exist
- Read More is not working in query posts
- query_posts for child pages
- How to reverse the order of WordPress blog posts?
- orderby:date not working
- Trouble with get_next_post() get_previous_post() returning null
- Possible to display posts containing a short code ?
- How to run a SQL Query for character in Post Titles
- Authors List page : how to exclude posts from certain category
- list child page items (1 level with meta keys)
- Query a WordPress page by its title (which has a parent page)
- post_parent array doesn’t work
- number of posts per page + random + exclude categories
- How can I override one post and make it display content for another post?
- How to place an image after Nth number of posts in query_posts
- Related Posts: Notice: Undefined offset: 0
- query_posts pagination will always show identical content
- When to use WordPress loop or Foreach loop?
- Can’t get pagination to work for sticky posts only
- show x number of posts from y category on homepage
- How to Show Comment Count on Related Posts?
- Change the destination of the URLs in post.php
- How can I show only 5 posts from the relationship?
- Make query_post category name dynamic
- query_posts orderby postmeta [closed]
- WordPress Query based on random taxonomy
- Displaying and Querying Posts with Featured image
- Restrict query_posts by Date?
- Sort post by custom field numeric value
- Notting but the latest post content keeps on being loaded
- query_posts doesnt show pages with given ID when post_type => page
- How to put posts in pages using query posts
- Query add html after set amount of posts?
- Custom loop off by one post
- How to setup blog page to render blog posts minus afew categories
- How to get max value of filtered query post
- Ordering of posts, 2020 Year showing as next event when should be last
- Pagination doesn’t work in query post in tag template
- My entry results are not consistently alphabetized
- How to display most popular post by views count in WordPress?
- Why I obtain this WP_Query strange behavior trying to select posts having a specific tag?
- query multiple posts by id using a string parameter, not array()
- How to grab data (titles, thumbnails and custom fields) from multiple posts to populate a new array efficiently?
- query_posts – slightly more advanced query
- Query posts in a category and include only one post per author?
- Query Posts Creates 404 Error
- Does wp_query and query_posts affect website performance? [duplicate]
- Achieving pagination with `query_posts`
- ‘Active lotteries’ only custom query for woocommerce lottery plugin and elementor