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
- Does anyone have any frameworks to setup custom post types and related actions/filters?
- Is it proper to create a page just to generate a listing page (eg. for a custom post type)
- How to quickly switch custom post type singular template?
- Where to put archive-{post-type}.php
- Using Custom Templates for Custom Post Types for the Genesis Theme Framework?
- Turn query string to sub page
- WordPress Template Hierarchy
- Is it possible to place custom post type files inside a folder in theme directory?
- Set up Custom-Post-Type Author Archive
- One-to-many post relationships that are displayed by category (using posts-to-posts plugin)
- Am unable to reset a query properly
- Get next and previous 3 posts in a term in single post page
- How to change the post type a theme shows by default?
- WordPress Doesn’t Generate Taxonomy Archive
- How to produce a sub-page-system in WordPress
- WordPress custom taxonomy template not working
- WebP Fallback for Inline Background Image in Style Attribute
- WP Query post__in not returning correct results
- How can i link a custom post type thumbnail to intermediate size
- get_post_meta is not working inside shortcode
- get_pagination not working on a custom post type query (using WP_Query)
- How to Make infinite loop of post
- How can I trace inconsistency in loading a template?
- Assigning alternate single-{cpt} template based on blog_id in multisite
- postsperpage value not being applied
- Custom Post Type – after disable ‘Add New’, I can’t edit and delete post
- Multiple Loops on a Page Without Duplicates
- Custom permalink structure for remote content pages
- How to customize `Edit-Post` Screen
- Use Author Ids or Names to echo different output inside loop
- Specifying a template for custom post type pages
- Custom Post Type, Pagination and 404s?
- Custom post type set default template using block editor
- Is it possible to link an external stylesheet, exclusively within a specific single post template?
- Display all posts from specific category and CPT
- posts_per_page is not working by term
- How to display only child category post in related posts in custom post type?
- % encoded URL giving 404 error in WordPress
- CPT: multiple loops with different terms
- Custom post type option page template
- How can I find out what template is my custom post type using?
- Links Image in “Catalog” Page to Posts
- All custom posts are not showing up
- WordPress query posts by custom post type not workng
- Not Able to Get Custom Post Type in Single and Single-custom-post-type
- Using piklist meta box, strange behavior
- Redirect to different template other than single-custompost.php
- Loop posts in a table ordered by a custom field value
- Custom Loop Event Page
- How can I detect a chosen Isotope layout option from within Javascript to generate appropriate layout?
- Storing postID in session variable to query database when visitor on custom template page
- Turn post into simple slideshow
- Fourth page of custom post type archive page does not exist
- Apply text based styling done for a single post in WPBakery to all posts / create a template out of it [closed]
- Render a loop in Timber (twig for WordPress)
- Why isn’t page attributes dropdown not showing up in a custom post type