There is built in support for that, kind of. While I don’t see anything wrong with your code, try naming your files on the form archive-mytype.php
, content-mytype.php
etc. and then call get_template_part
like this:
<!-- This will result in including parts/content-mytype.php -->
<?php get_template_part('parts/content', get_post_type( $post )); ?>
<p id="t3-splash-title"><?php $post_type = get_post_type_object( get_post_type($post) ); echo $post_type->labels->singular_name ; ?></p>
Related Posts:
- Passing variables through locate_template
- How to use get_template_part()?
- Is there a variable for a template parts name?
- How to make get_template_part always check child theme first?
- Check if partial file is called from within header.php or footer.php
- Too many get_template_parts?
- get_template_part() does not work if you call it when you are in a subfolder
- Pass a variable to get_template_part
- get_template_part inside get_template_part?
- Getting the chosen template when iterating through pages
- Possible to use pagename inside get_template_part?
- Why would include(locate_template) work but not get_template_part()?
- How does get_template_part() work inside a loop?
- Is there a tirck in the get_xxxx function in the general_template.php file?
- Problem with using get_template_part() in footer
- how to remove get_template_part from a plugin? [closed]
- get_template_part() based on get_post_type() for a custom post type instead of get_post_format()
- add a hook with get_template_part()
- ä/ü/… are not displayed when including via get_template_part()
- Change the file path on get_template_part via plugin
- How to limit the number of Related Posts?
- get_template_part – how to find html file which is being render
- Get_Template_Part And Two Global WP_Query On Frontpage
- The use of get_template_part() returns ‘invalid argument’ loading options
- Passing a variable from the archive page to the default template
- For which reasons can get_template_part’s $args fail to work? (WP 5.8.1 – PHP 7.4.23)
- Can I set a global base path for get_template_part?
- how to use a different template (index.php) in wordpress
- What are the benefits of using get_template_part()?
- Include template file from plugin to theme
- get_template_part doesn’t output all data
- Is there any way to use get_template_part() with folders?
- When is get_template_part() preferable to simply using the template.php files?
- Combining shortcode and get_template_part
- Variable use in get_template_part
- Get template part vs locate template function
- Single Page WordPress Theme – Using page templates
- _wp_page_template to dynamically use template
- Templates & CSS – Proper Programming Practice?
- Which custom query am I in and how can I access its properties & methods?
- Accessing $post variable from template part
- get_template_part not working with ajax
- Passing variables to template parts
- Correct way to use get_template_part() and get_post_format() with custom post types?
- How to pass variables with get_template_part?
- How to localize inline script called with ajax
- Unable to include a template
- How to make get_theme_mod work with AJAX in the customizer preview
- Checking whether template part is loaded in a page
- Where is the template for the ‘standard’ format of a post in the theme twentythirteen?
- Valid HTML in Template Part
- Unexpected results with conditionals inside template part
- get_template_part and template file names
- how could I load a different template part by page
- Get_template_part inside a folder
- Problems with loop
- Conditional get template part
- Don’t see add_filter result in the site front page
- Showing the WordPress standard text area on a Woocommerce Single Product Page?
- Modify foreach loop for social sharing links?
- Modal working only on home page
- Detect if current page is front page within custom query
- Loading template parts conditionally in Customizer
- How do I display an image before the first post of the loop when I’m using get_template_part?
- Using same variable names in files added with get_template_part()
- Check for the main query from the template
- get_template_part() doesn’t work
- how to replace get_template_part(‘loop’,’tag’) with explicit styled version?
- Custom post type index (maybe using get_template_part)
- Using ob_start and ob_get_clean with wordpress shortcode
- How to pass a variable to get_template_part that’s updated every time the template part is called?
- Does get_template_part() content gets parsed if it’s not executed?
- Get_template_part seems to be ignoring my template
- using get_template_part() inside a widget and passing variables
- Is there a way to retrieve the calling template part?
- How can have a conditional template tag based on the main loop within a secondary loop with new WP_Query(), using get_template_part()
- Is there a way to call on just the content of a Page without actually using that Page? [closed]
- Is “get_template_part” hierarchy possible?
- Is it possible to have a Theme with built-in physical page files?
- On click some element i want to use some template
- How to get all template files used for rendering a single post/page?
- Template not loading with get_template_part or locate_template
- Load templates, pass arguments, and render output from functions.php
- Adding a second loop breaks everything
- Ajax and get_template_part
- Is_Page doesnt detect my page
- Display a custom 404 page without a redirect
- Remove a short code and update it’s content (AJAX)
- How to get value from radio buttons meta box, and return different contents?
- How can I show contents of a template part inside of another page?
- Call get_template_part() custom permalink
- Use another theme template in my theme
- When to use content-pagename.php?
- Theme parts path location dump
- How to unregister sidebar for template_part?
- how to modify request to get_template_part()?
- what template-part to call, to have my post in the center of the page?
- If I define a variable in header.php, how do I make it available to templates?
- Headers already sent error with get_template_part in REST API call
- get_template_part() does not render after the ajax request