I don’t have a full detailed response for you, but here’s a few things I’d suggest:
1) Use template parts for each of those segments. That will help clean up the template so it’s easier to work with in the future. ( see here: https://konstantin.blog/2013/get_template_part/ )
2) You could then create a helper function for the entire query, basically get EVERYTHING, then have login in the helper function to filter the results. So that within each new template part you’d have something like this:
prefix_index_query($posts_per_page = 3, $post_status="publish")
See here: https://tommcfarlin.com/wordpress-helper-functions-for-templates/
Those two things alone will get you going in the right direction for a much cleaner file structure.
Related Posts:
- Different ‘posts_per_page’ setting for first, and rest of the paginated pages?
- How to adjust found_posts so that it accounts for offset and pagination
- WP Query with offset breaks wp_pagenavi or any pagination
- Exclude first 5 posts of specific categories in the main loop
- Custom query, works, but I get a “Notice: Undefined offset: 0…”
- Offset Page Loops and Pagination
- Storing query variable and then using wp_reset_query
- While creating Block Themes in WordPress, how can I query custom posts for an Archive view?
- How to use offset in WP_Query
- How can I fix: “Notice: Undefined offset: 0”?
- WP_Query, pre_get_posts and offset
- Why does get_posts only show results for Admins or logged-out users?
- WP_Query with offset and ‘orderby’ => ‘rand’, offset not working
- How do I rewrite this loop as a new WP_Query style-loop?
- WP_Query arguments order
- WP_Query – Adding “offset” posts to the end of the loop
- Stomping WP_Query in author archive to facilitate pagination with custom queries
- Apply query arguments after the nth post
- AJAX Breaking Offset Argument In WP Query
- Page navigation doesn’t seem to work when I add offset?
- WP_Query offset is returning post from prevois loop
- Need help understanding this WP Query [closed]
- Offset WP_Query by negative 1
- WP_Query Orderby meta_key and hide some meta_key
- setting offset to category number in archive page
- Featured Image as Background with Offset
- WordPress WP_Query offset parameter not working with search parameter
- Multiple homepage layouts as selected by user from theme options
- wp query problem
- Multiple WP_Query with pagination shows Page/2 content on the remaining pages
- What is the best way to offset previous posts on the same page?
- query loop “inherit query from template” prevents setting sort order
- WP_Query offset returning duplicate posts from previous loops with AJAX
- When should you use WP_Query vs query_posts() vs get_posts()?
- When to use WP_query(), query_posts() and pre_get_posts
- WP_Query by just the id?
- Meta_query compare operator explanation
- WP_Query with “post_title LIKE ‘something%'”?
- wp query to get child pages of current page
- How to get an array of post data from wp_query result?
- How to get post id of static front page?
- meta_query with meta values as serialize arrays
- How to only display posts whose meta_value field is not empty?
- Get post ids from WP_Query?
- Pagination when using wp_query?
- Exclude post ID from wp_query
- How to print the excuted sql right after its execution
- How to extend WP_Query to include custom table in query?
- How to store and receive variables in WP sessions?
- Should I use Pre Get Posts or WP_Query
- How can i retrieve default post per page value? from settings->reading. And total number of posts?
- Nested meta_query with multiple relation keys
- Is it necessary to use wp_reset_query() in a WP_Query call?
- Can I force WP_Query to return no results?
- Can wp_query return posts meta in a single request?
- Using pre_get_posts with WP_Query
- Find out total number of pages in global query on archive page?
- WP_Query + random
- Resetting post data to previous loop in nested loops
- order by numeric value for meta value
- numberposts? showposts? posts_per_page?
- $GLOBALS[‘wp_the_query’] vs global $wp_query
- Broken? WP_Query and “attachment” as a post type
- Some doubts about how the main query and the custom query works in this custom theme?
- Order by multiple meta key and meta value [closed]
- Post_count only shows the number of results per page
- Page template query with WP_Query
- meta_query ‘compare’ => ‘IN’ not working
- Query posts only with featured image
- Wp get all the sub pages of the parent using wp query
- What is appropriate flow for custom data from URL in WP_Query?
- How to display page content in a page template?
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- How to merge two queries together
- Posts with at least 3 tags of a list of tags
- Get post count of current loop when using multiple queries on one page
- why ignore_sticky_posts in sticky post query
- Wp_redirect and sending variables
- Multiple relationship for multiple tax_query in WP_Query
- How do I get posts that have a thumbnail in WP_Query?
- Multiple WP_Query loops with Pagination
- How do I query for posts by partial meta key?
- Pagination with custom SQL query
- Return only Count from a wp_query request?
- Using a custom WP_Query with get_template_part loop
- Use REGEXP in WP_Query meta_query key
- Why is the loop not empty on some 404s?
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- WP Query Args – Title or Meta Value
- How to query for most viewed posts and show top 5
- WP_Query orderby date not working
- WordPress Pagination Not Working – Always Showing First Pages Content
- Best way to detect if you are in a SINGLE POST page
- Meta query with string starting like pattern
- WP Query where title begins with a specific letter
- WordPress tax_query “and” operator not functioning as desired
- compare meta_query in get_posts arguments
- Custom taxonomy query broken after upgrade to 4.4
- WordPress retrieving meta data for all custom post types in list view
- How to query posts based on lat-lng coordinate as post meta?