I think you are doing this right… but in the wrong direction. What if you separate your default structure like:
content-header.php
<?php get_header(); get_sidebar(); ?>
<div id="content">
content-footer.php
</div>
<?php get_footer(); ?>
And then you can use get_template_part to put all together:
index.php
<?php get_template_part( 'content', 'header' ); ?>
<?php
while ( have_posts() ) {
the_post();
the_content();
} // end while
?>
<?php get_template_part( 'content', 'footer' ); ?>
page-template.php
<?php get_template_part( 'content', 'header' ); ?>
// [special template php code]
<?php get_template_part( 'content', 'footer' ); ?>
Related Posts:
- Assign a template to a custom post type when displayed by the main loop on the home page
- Assign single template to multiple custom post types?
- How to set a fall back template for a custom post type in a plugin?
- Custom Post Type Archive URL takes over page URL
- How to query custom posts using a dynamic category
- Posts in Multiple Columns and Rows with one single loop
- Template tags to display custom post type posts in category template?
- Group search results by post type, but hide post types with no results
- Custom post type loops with different page templates
- How to get current post id of a custom post type in a loop using template singel-{custom type}.php?
- Integrating Orbit slider into wordpress through custom post type
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- What is the recommended / best way to do this: Event calendar post/type in a block-based theme?
- Return the latest post from a custom Taxonomy and Post Type
- How to specify a template for a path like http://example.com/something?
- Main query not querying any posts in custom taxonomy template
- Custom WP_Query doesn’t display all posts
- Two column layout with alphabetical ordering
- WP_Query with custom post type ID
- assign different templates to custom post type with homepage loop
- Custom Post type content within a slider
- Create a custom taxonomy template that loops through child categories in term order?
- On click some element i want to use some template
- How to Enable Ascending or Descending In WordPress Default Built-in Loop
- How to display posts from a certain category in a bootstrap 5 carousel loop with multiple items?
- Loop all post on single.php
- Post template not applying on theme (potentially rendering as Page template)
- Add extra elements to the_post in a custom post_type
- Custom Post Taxonomy Template Not Loading Properly
- Accessing download link from the loop with WP Download Manager Pro
- Custom Post Type has wrong label and is not found when called by a loop
- Custom post type single page uses the right template in preview mode but shows a different template after being posted
- Custom taxonomy template for custom fields loop [closed]
- get_permalink() of page the enclosing page not posts
- Values show up in custom home page but not in custom post pages
- 2 custom posts types, in their own columns, one pagination for both
- Custom post type with custom taxonomy permalinks
- Custom taxonomy page template
- Cant insert wrapper div into index.php
- Load different template for CPT (in loop) in my plugin?
- How can I pull information from my loop and divide them seperately?
- Having some trouble properly displaying Custom Post Types in templates
- Create custom post order (with custom post type meta)
- WordPress search results grouped by post type
- How to check if a custom post type uses a custom template?
- Custom PHP Template in Twenty Twenty-Four
- How to change single custom post template by custom taxonomy?
- Ideas to connect external database table to wordpress posts as custom field source
- Custom Post Type homepage template
- Having Issue on Getting Metabox Checkbox Value
- Multiple Loops on a Page Without Duplicates
- Display post from custom post type
- Use post in multiple places on a page with multiple posts
- List all Custom Post Type posts excluding certain Taxnomy term
- Searching post types
- Custom permalink structure for remote content pages
- Query all post types but limit to parents
- Custom meta box in custom post type not working
- WordPress giving a 404 page when passing a year argument different than the current year
- Add admin script to several post types
- foreach loop inside the loop creating duplicates in output
- Add Class according to the order of appearance
- Custom Sidebar in Editor (not Widget) for Custom Post Type in Genesis
- Loop Post Types with Name and Links
- Setting a homepage – doesn’t seem to work
- Display all images from specific CPT
- The loop does not show users
- How to create a archive template for custom post type [duplicate]
- Custom loop to query posts with no featured image and/or no post editor content
- WP not recognizing custom post type / template
- Compare Two Custom Post Types Using The Same Custom Taxonomy
- Looping through custom taxonomy and display custom post types (Custom Post Type UI)
- How to retrive Custom Post Type Meta Fields in Custom WP_Query
- Archive Template being used instead of Category Template for Custom Post Type
- Displaying information from custom field on custom post type
- Custom post type draft use wrong template
- List of a specific Custom Post Type in Custom Template
- Why does my URL keep returning 404 error code?
- pre_get_posts works in post type archive but not in single post
- Display only a single CPT
- Custom post class, generate unique id from 1 to x depending on amount of posts?
- Control Loop Within Loop
- Custom post type hierarchical loop in Homepage
- How to fetch posts that are stored in the different table than (default) wp_posts?
- Why is the output of a call to the_excerpt different when the call seems to be identical?
- Cant’ Display Custom Post Type Title Base on Tax Terms
- Display Posts Query with IF function
- My template won’t apply, theme still fallback to index.php
- Permalinks for single-[custom-post-types] not working
- How can I add in post’s the text “No content”
- Custom Post type showing up in loop, regular posts are not showing up
- Loop and add Specific Categories and Products Images
- Get post-meta value of all custom-posts – lowest to highest year-count?
- Loop for custom-post-type comparing taxonomy terms for “related” posts?
- Require custom post type if is_admin() – template doesn’t show up?
- How do I enforce a specific custom post type on the loop
- Make Next and Previous on single-$posttype.php use the same order as archive-$posttype.php
- Custom Post Type – Main page for certain posts
- CPT archive page – show one post from each taxonomy term
- How to customize `Edit-Post` Screen