带内容的自定义模板

我们将进一步扩展我们的模板,包括页面标题和内容

<?php
/*
Template Name: Example
*/
get_header();
    
the_title();
the_content();
    
get_footer();

如果你想要,你可以用这样的 HTML 元素包装它们

<?php
/*
Template Name: Example
*/
get_header();

echo '<h1>' . the_title() . '</h1>';
echo '<section> . 'the_content() . '</section>';

get_footer();

或者,如果你喜欢像普通的 HTML 文件一样工作,而不使用 echo

<?php
/*
Template Name: Example
*/
get_header();
?>

<h1><?php the_title(); ?></h1>
<section><?php the_content(); ?></section>

<?php get_footer(); ?>