0

すべてのカスタム テンプレートを含む front-page.php を持つ単一ページの Web サイトがあります (それぞれが静的ページです)。

<?php get_header();

$args = array(
    'sort_order' => 'ASC',
    'sort_column' => 'menu_order',
    'post_type' => 'page',
    'post_status' => 'publish'
);

$pages = get_pages($args);

foreach ($pages as $page_data) {
    $content = apply_filters('the_content', $page_data->post_content);
?>

<?php echo "$content" ?>

<?php
}
get_footer();
?>

「the_content」を使用すると、バックエンドのテキストのコンテンツのみが参照されますが、テンプレート自体の the_content タグを囲むすべてのタグは参照されません。次に例を示します。

<?
/*
    Template Name: Features
*/

    the_post()
?>

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<section>
    <? the_content() ?>
</section>

<?php endif; ?>

この場合、周囲のタグセクションは選択されておらず、マークアップに表示されません。

テンプレートだけでなくテンプレート全体を選択するには、front-page.php で何を変更する必要がありますか?

よろしくお願いします!

4

1 に答える 1

0

get_template_part各ページ テンプレートのループ パーツを別のテンプレート パーツに配置し、フロント ページで次のようにパーツを動的に呼び出すことができます。

foreach ( $pages as $page_data ) {
    $template = get_post_meta( $page_data->ID, '_wp_page_template', true ); // get page template path
    $template = substr( $template, 0, -4 ); // chop off .php from the string
    get_template_part( 'loop', $template );
}

テンプレート 'Features' (ファイル名features.php) の場合、 などを探しますloop-features.php。フォールバックはloop.php.

于 2013-05-30T13:15:22.053 に答える