0

スラッグ /en/work/ を含む子ページがあり、スラッグによって見つかったページ テンプレートを使用したいと考えています。page-work.php と page-en-work.php の両方をアップロードしましたが、ページに移動すると、どちらも使用されません。

4

1 に答える 1

1

次のリンクを見てください

http://codex.wordpress.org/Function_Reference/get_template_part

<?php while ( have_posts() ) : the_post(); ?>
  <?php get_template_part( 'content', 'page' ); ?>
  <?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>

カスタム ページ テンプレート ("my_child.php") には、次のようなファイルを含めます。

<?php while ( have_posts() ) : the_post(); ?>
  <?php get_template_part( 'content', 'my_child' ); ?>
<?php endwhile; // end of the loop. ?>

get_template_part を他のページにも含めることができるようになりました:

 <?php

    global $wp_query;

    // is Page a parent page
    if ( $post->post_parent == 0 ) {

        // on a parent page, get child pages
        $pages = get_pages( 'hierarchical=0&parent=' . $post->ID );

        // loop through child pages
        foreach ( $pages as $post ){

            setup_postdata( $post );

            // get the template name for the child page
            $template_name = get_post_meta( $post->ID, '_wp_page_template', true );
            $template_name = ( 'default' == $template_name ) ? 'page.php' : $template_name;

            // default page template_part content-page.php
            $slug = 'page';

            // check if the slug exists for the child page
            if ( locate_template( 'content-' . basename( $template_name ) , $load, $require_once ) != '' ) {
                $slug = pathinfo( $template_name, PATHINFO_FILENAME );
            }

            // load the content template for the child page
            get_template_part( 'content', $slug );
        }
    }
    ?>
于 2013-09-10T06:42:57.283 に答える