Sử dụng locate_template (ok)

<?php  
    // Trong functions.php
    if ( $overridden_template = locate_template( 'some-template.php' ) ) {
       // locate_template() returns path to file
       // if either the child theme or the parent theme have overridden the template
       load_template( $overridden_template );
     } else {
       // If neither the child nor parent theme have overridden the template,
       // we load the template from the 'templates' sub-directory of the directory this file is in
       load_template( dirname( __FILE__ ) . '/templates/some-template.php' );
     }
?>
<?php
Tạo file some-template.php
Bạn có thể không cần đoạn comment sau đây :)))
/**
* Template Name: Some
* @package WordPress
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/
echo "Lorem";
?>

Last updated