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)
- Set Alias for meta_query arguments in get_posts()
- Loop within a loop?
- WP_Query meta_query where meta value ends in space
- Using Query Posts With Multiple Post Types And A Taxonomy
- WP_Query to get posts in a specific category and post format
- Multiple instances of Featured Image Query
- Can’t get drafts with WP_Query using post_status parameter
- Storing query variable and then using wp_reset_query
- Get a list of posts with associated meta_value
- $WP_Query: How to display excerpt on first post only
- database query with more than a couple meta hangs and doesn’t complete
- get_template_part causes 500 error
- WP_Query – Adding “offset” posts to the end of the loop
- wp_query is showing posts from other categories
- it’s possible make a WP_Query with math operations?
- Max Posts and Memory Limit
- ACF: How can I publish values of ACF fields in a loop while using wp_query?
- meta_query compare > not working
- Paging works correctly on local version, but not live?
- Filter posts/pages by user_role array
- Pagination not working with WP_QUERY
- WP_Query with meta_value_num and meta_query not paged correctly
- Sort Posts with custom meta key by default which is currently set as optional
- wp_query pagination links producing 404
- Pagination problem with multiple loops on the same page