You can control what template loads for any type of query via the Template Filters.
Here’s an example using home_template that checks if posts_per_page is equal to 1, and loads single.php in that case.
function wpd_home_template( $home_template="" ){
if( get_option( 'posts_per_page' ) == 1 ){
$home_template = locate_template( 'single.php', false );
}
return $home_template;
}
add_filter( 'home_template', 'wpd_home_template' );
Related Posts:
- How to provide meta_key array to wp_query?
- Nested meta_query with multiple relation keys
- Some doubts about how the main query and the custom query works in this custom theme?
- WP_Query vs get_posts
- Display products from specific category in shop page
- Order posts by ID in the given order
- Query Multiple Post types each with own meta query
- Get the number of posts from the current page results
- WordPress Custom Query to show posts from last x years
- Query Custom Meta Value with Increment
- Perform query with meta_value date
- Meta Query with date and time on the same Day before given time
- How do I create my own nested meta_query using posts_where / posts_join?
- Exclude post on loop by multiple meta key value
- Query sticky posts with thumbnails
- 2 loops on page – one with orderby rand second orderby date
- Order a query result by a numeric meta key even if it does not exist, but put the posts with meta key first
- WP_Query on custom field and order results
- Query posts by specific word on title
- WP_Query last five posts, simply ordered by meta_value
- Five posts from a category in footer
- Multiple loops without repeating content
- Any number in meta key (wp query)
- WP_Query condition affects posts_per_page count
- Fetch Record based on meta key dates
- How to display multiple custom fields with the same meta_key in an ascending order?
- how to make members list directory through wordpress post custom meta key.
- Some doubts about how the main query and the custom query works in this custom theme?
- Array as ‘key’ in WP_Query
- How do I rewrite this loop as a new WP_Query style-loop?
- Include current post into loop
- Wp_query with 2 meta keys and array of meta values
- get_posts output always same post
- How to create custom query by keyword in post title?
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Conditional operator OR not working with custom fields
- Get posts that do not have the same tags as current
- Should I reset $wp_query?
- Meta query compare for ID’s greater than specific ID
- 2 queries with counters
- Show single posts date, in a page of posts
- Why doesn’t my WP Meta Query return any results?
- Paginate pages with dynamic query
- Performance concerns: index.php vs taxonomy-$taxonomy.php
- Determine if ID is page or post and query the ID
- Custom template for password protected page
- WP_Query Class custom field parameters
- Use have_posts() with array of post results retrieved by $wpdb->get_results
- Magazine style frontpage with multiple categories/loops and no duplicate posts
- WP_Query not returning correct result with meta_query parameter
- How do i create a custom post query when the meta value is an array?
- Duplice post with standard WP loop – fixed by using query_posts() instead
- ElasticPress is (aparently) messing with my search filters
- show most viewed post
- How do I stop the same post showing multiple times in a archive?
- Query for current post
- Custom query to retrieve oldest post and retrieve others with date interval
- Custom query for custom post type not getting correct post ID
- Problem with my loops
- WordPress For Loop Prints Unwanted Extra Paragraph Element
- Meta Query if Values Don’t Exist
- Orderby query does not work for custom fields even with meta query
- How to order posts, that have already been filtered by custom taxonomy, by their category names?
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- Custom WP_query and integrating into theme file
- query_posts() doesn’t seem to be called in my page
- Some doubts about how the main query and the custom query works in this custom theme?
- Ordering Posts by parent category, name ascending
- Custom loop – Isolating post meta output depending on current query taxonomy terms
- Limit the number of posts from a specific category on index.php
- query post based on comparison
- Converting an existing query_posts to WP_Query
- Multiple loop for “featured” items returns wrong posts
- WP Query – Show custom posts only if user contain some user meta
- Show number of posts AND number on current page (cannot make it work)
- Use REGEXP in WP_Query meta_query key
- Build a content and excerpt grid loop with paging and options for # of posts
- search query within custom taxonomy term, post title and meta field
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- Loop inside the loop
- Sort by meta key on archive page
- Retrieve or Query Pages by ID
- Large AND OR query timing out
- Custom loops, sticky posts, and pagination nightmare
- How to make a second query offset -2 from current post
- meta_query: check if number exists
- Create a loop on my pages with new “WP_Query”
- WP ForLoop to compare meta information of posts to determine what post to display
- WP Query / Meta Query [duplicate]
- Query multiple post types, but different order for each
- Multiple nested meta queries
- Comparing Meta Field date in WPQuery using Meta_Query?
- datetime picker, timestamps and meta queries
- WP_Query with meta_query won’t orderby
- Extending WP Query: Custom geolocation meta values work, but tax_query breaks
- WP_Query for attachments without duplicating post_parent and displaying tagged image
- List ALL posts within last week from current category on category page
- WordPress pagination returns the same posts
- Use value from meta key array for use in WP_Query
- Pagination only showed when no category is set in wp_query