I'm writing a custom theme. Most of the content will use the regular index.php
, header.php
and footer.php
.
The index.php looks like
<?php get_header(); get_sidebar(); ?>
<div id="content">
<?php
while ( have_posts() ) {
the_post();
the_content();
} // end while
?>
</div>
<?php get_footer(); ?>
But there will be some pages with special content, so I need to write custom templates php files that I assign to some pages. Now, in order to embed this special content within the main frame of the website, I have to do
<?php get_header(); get_sidebar(); ?>
<div id="content">
<?php
// [special template php code]
?>
</div>
<?php get_footer(); ?>
in every custom template. As you can see, this is the exact the same, just with the main loop replaced by custom content. I'd like to avoid code duplication as much as possible. So, that in my template I only have to put [special template php code]
instead of the whole framework.
Is there convenient way to use the default frame that is defined in index.php
(header, footer, sidebar, etc.) without having to call the functions in every template again and again?
I thought about some php switch
in index.php
, but this has to be maintained as well (if page id changes for example, if I use page id's as the switch variable). Or if I intend to do changes on the <div id="content">
I would have to do it in every template as well. I'd like to avoid this.