wordpress不在the_content()或footer.php中加载

时间:2016-01-06 13:47:49

标签: php wordpress

我正在创建自定义主题,但遇到了一些问题。有关您的信息,我的文件如下所示:

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

?>


<?php
if ( have_posts() ) {
    while ( have_posts() ) {
        //
        // Post Content here
        the_content();
        //
    } // end while
} // end if
?>


<?php get_footer(); ?>

这是我的header.php

<footer>
<div class="container">
    <div class="col-sm-6">
        A&D AQUATIC & GARDEN CENTRE | WEBSITE DESIGN BY <span>MATTHEW SMART</span>
    </div>
    <div class="col-sm-6 text-right">
        <ul>
            <li>TERMS AND CONDITIONS</li>
            <li>PRIVACY POLICY</li>
            <li>COOKES</li>
        </ul>
    </div>
</div>

</footer>


</div><!-- End WRAP -->
<?php wp_footer(); ?>
</body>
</html>

这是我的page.wide.php

ArrayList

这是我的footer.php

loop

现在我尝试测试的页面正在使用宽模板。我在编辑器中放了一些虚拟文本,然后点击发布。

现在,当我尝试访问该页面时,我能看到的第一件事就是标题的一部分。然后浏览器再花5秒钟加载我的header.php文件中的导航。

似乎只是忽略了页面模板中的所有内容以及之后的内容。所以the_content()没有任何内容,页脚也没有显示出来。

我一直在将这些文件与我创建的其他主题进行比较,似乎无法找到原因。

有谁知道为什么会这样?

由于

1 个答案:

答案 0 :(得分:1)

您的循环缺少the_post()。

<?php
if ( have_posts() ) {
    while ( have_posts() ) {
        the_post();
        //
        // Post Content here
        the_content();
        //
    } // end while
} // end if
?>

https://codex.wordpress.org/Function_Reference/the_post

这是让WordPress知道你在循环内部并检索所请求的帖子数据的必要条件。页脚没有加载,因为页面在调用the_content()时出错,并且无法在循环外处理此函数。

根据WordPress documentation,the_content“必须在The_Loop中。”