You said you’re in a custom loop that returns various post_types:
//.....
while ( $loop->have_posts() ) : $loop->the_post();
get_template_part($post->post_type,'layout');
endwhile;
in this way you don’t use extra conditionals and relying on get_template_part() you simply need different files post_type1-layout.php
, post_type2-layout.php
, etc.. in the root folder of your theme / child theme keeping the templates separate, cleaner and more usable.
Also you can put the template files in a subfolder customTemplates
and use
get_template_part('customTemplates/'.$post->post_type,'layout');
Related Posts:
- Jquery Slider for profile template
- if ( is_home() && ! is_front_page() )
- Is including the loop necessary for page.php? [duplicate]
- What is best way passing variables to theme templates and using them different places like widgets?
- Page template not displaying
- Loop through pages with specific template
- How to get_template_part using AJAX?
- wp alchemy multiple image uploader output images to template
- code suddenly appearing from my tempate second loop
- Get search.php results in header.php?
- WordPress Loop inside Loop?
- How to show “teaser” posts on blog / archive pages, otherwise full posts
- Order archive results by post id in custom taxonomy template
- Default ‘post’ post type archive slug?
- How do I make a variable available inside partials?
- 404 Template customization | Want 10 recent Post on the 404.php error page apart from the error Notice
- Second Loop Showing Only One Post on Single Post Page
- How do I put my frontpage featured image in a page template for home.php?
- Get markup for post without loading into the template
- How to render the single post template with the post name?
- excerpt not showing up
- new custom theme – posts displaying on top of one another
- How do i create a list-posts-page?
- How to sort a loop after most viewed
- How to loop specific Category menu from archive page?
- How do I set the Stewart Search Template to return only published posts in the result
- Is it possible to set archive.php instead of index.php to display blog?
- Using is_page_template inside loop
- is it bad to copy the loop for a template?
- Is “the loop” a template tag?
- Deeply Nested Menu Loop with Twig using Timber [closed]
- WordPress with woocommerce custom query
- Alternative layout the loop
- Cant pull in featured Image
- Template included with plugin doesn’t return all posts for custom taxonomy
- Creating a archive for taxonomy terms, not the term results
- Secondary loop cuts off at 10 posts?
- Need a conditional to test if title of parent page matches title of child page
- get all page templates
- Load featured article once in a loop
- wordpress showing all posts instead of date range
- How to implement template file and the loop
- Same posts within a paginated page
- How can I create an entirely new, separate display of posts?
- Get excerpt using get_the_excerpt outside a loop
- Should I use loop in the single.php file?
- wp_list_categories: get latest featured_image of category
- Posts in Multiple Columns and Rows with one single loop
- WordPress Alphabetical Glossary close div in loop
- Exclude filter on front page
- category__not_in — anyway to use category name instead of id?
- Filtering posts by multiple taxonomies
- Exclude first 2 posts with meta_key from loop
- Make a custom loop inside single.php with pagination
- Why do I get `Call to a member function have_posts() on a non-object `? [closed]
- Help with Changing loop.php?
- How to split a loop into two columns
- Category Ajax call
- Transient loop issue
- popular post weekly and monthly
- How can i use the same template file with a widget and category loop?
- Custom Loop Using Shortcode in Custom Page Template
- Listing subpages title and content and styling the first iteration differently
- single.php – how to mark current page in the loop
- Cannot retieve the_content() and the_author() – both returning empty strings
- How to order by multiple fields using standard query_posts?
- Get 1 more post in loop
- Make loop alphabetical
- How to check if a product is purchased within the last 365 days before displaying something
- How do I get my loop.php to properly paginate?
- How to display first post
- Pagination on custom post type on front-page.php
- get_template_part() Not Working in Loop
- get_delete_post_link() inside Loop stubbornly returns nothing
- CPT while loop not working
- Problem with Front-Page.php loading recent posts
- Comments_template doesn’t work
- Where to add offset?
- How to synchronize The Loop with the max post per page?
- How to add a byline to all the pages?
- Displaying member join date on page
- Ascending order has strange effects on wordpress loop
- get post images to link to external sources
- Slug is changing when I use WP_Query in a metabox of a post
- Custom loop not working in singular.php, working in other pages
- Loop Posts Outside of WordPress Installation
- Strange problem with wp_get_attachment_image_src database (db) query count
- How to include posts from one category, into a separate category of posts?
- how do i make this loop work
- Making a specific page wordpress compatable that is not index
- change the_content images for different sizes (Desktop, tablet, mobile)?
- display only parent replies count in index.php
- Redirecting posts in WordPress to a specific page
- Eliminate duplicates in a foreach loop [closed]
- Tag custom loop show posts
- While loop inside another while loop
- Question about custom plugin
- loop mix my child-category and parent-category
- Fix html inside a for loop [closed]
- Insert multiple custom components after x-number of posts