まあ、私はこれのための解決策を思いついた。それは最善の方法ではないかもしれませんが、これは私のために働いた。私は1ページのページを表現するために "home"というページを作成しました。このページのすべてのサブページには、ヘッダーまたはフッターを含まない特定のテンプレートがあります。
//fetch header as usual
get_header();
//fetch all subpages of this page
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page', 'orderby' => 'menu_order', 'order' => 'ASC'));
$children = get_page_children(get_the_ID(), $all_wp_pages);
//browse these subpages and get the content for each one
foreach($children as $child){
$post = get_post($child->ID);
getOnePageContent($post);
}
//footer
get_footer();
は今のfunctions.phpに、私はgetOnePageContent定義:
function getOnePageContent($page){
global $post;
$post = $page;
$slug = get_page_template_slug($page->ID);
if($slug){
$pl = get_the_permalink($page);
$content = file_get_contents($pl);
echo $content;
} else {
$content = apply_filters('the_content', $page->post_content);
echo $content;
}
wp_reset_postdata();
}
限り、サブページが、これは正常に動作ヘッダーやフッターが含まれていないとして、私の自宅のテンプレートは次のようになります。もちろん、私はfile_get_contentsでページを取得するのはエレガントで良い解決策ではないと思っていますが、少なくともそれは機能します。
出典
2016-08-04 09:38:40
Chi
テンプレート全体を含めると、ヘッダーとフッターが再び含まれます。これは無効であるだけでなく、あなたが実際に望むものではありません。 – rnevius
テンプレートを複数のファイルに分割し、 'get_template_part()'を使ってそれらのファイルをインクルードすることができます。 – Jrod