首页 > 解决方案 > Wordpress - 无法获取我页面的内容。收到关于 post-template.php 的错误

问题描述

我正在编辑我的 page.php 文件并尝试在每个页面上显示特定的页面内容。我可以看到标题,但我收到错误的内容。

这是我看到的错误:

警告:count():参数必须是在 C:\xampp\htdocs\wordpress\wp-includes\post-template.php 第 310 行实现 Countable 的数组或对象

在搜索之后,人们说 PHP v. 7.2 有问题。我正在使用 PHP v. 7.3。人们还说他们应该停用任何插件,但我没有安装任何人。

这是page.php文件

<?php
    /**
    * Template Name: Mallsida
    */
?>  
<?php get_header(); ?>
<main role="main">
    <section class="page-bg" id="post-<?php the_ID(); ?>">
        <h1><?php single_post_title();?></h1>
    </section>
    <section class="page-content">
        <div class="container">
            <h2><?php single_post_title();?></h2>
            <p><?php the_content()?></p>
        </div>
    </section>
</main>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

标签: phpwordpress

解决方案


在您的情况下,问题是因为您没有使用默认的 wordpress 循环函数,然后调用 the_content 请参见下面的代码:

<?php get_header(); ?>
<main role="main">
    <section class="page-bg" id="post-<?php the_ID(); ?>">
        <h1><?php single_post_title();?></h1>
    </section>
    <section class="page-content">
        <div class="container">
            <?php 
            //modified here--------
            if ( have_posts() ) {
                while ( have_posts() ) {
                    the_post(); 

                    the_content();
                }
            }
            //finishing modification
            ?>
        </div>
    </section>
</main>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

另一个注意事项:

不要使用

the_content周围的标签仅使用块标签,如div、section 等


推荐阅读