如何在类似 public_html/test1
的目录中创建页面 有一个带有 header/sidebar/footer
的空白页我的实际模板。
我只能看到标题,没有侧边栏,没有内容(内容我的意思是“你好。”)。
我正在使用二十一十四模板。
这是我正在使用的 php 代码:
<?php
/*
* Template Name: My own page!
* Description: I made a page!
*/
require (dirname(dirname( __FILE__ )).'/wp-load.php');
get_header();
get_sidebar();
?>
Hello.
注意:如果我删除 the_content();
get_footer();
, 然后标题只出现但没有格式。
非常感谢任何帮助
最佳答案
内容没有出现,因为您的模板中没有循环。请将此代码添加到您的模板中,并将您的模板文件移动到 twentyfourteen 主题中的“page-templates”文件夹。
<?php
/*
* Template Name: My own page!
* Description: I made a page!
*/
get_header(); ?>
<div id="main-content" class="main-content">
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php
// Start the Loop.
while ( have_posts() ) : the_post();
// Include the page content template.
get_template_part( 'content', 'page' );
endwhile;
?>
</div><!-- #content -->
</div><!-- #primary -->
</div><!-- #main-content -->
<?php
get_sidebar();
get_footer();
附注如果您愿意,可以删除 div。
关于php - 带有我模板的页眉/侧边栏/页脚的 Wordpress 空白页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25880337/