我在本地服务器上遇到了这个问题。这个问题不是由于jetpack插件引起的,因为我已经删除了它
C:\xampp\htdocs\theme\wp-includes\post-template.php on line 284
Warning: count(): Parameter must be an array or an object that implements Countable in post-template.php on line 284
任何人,请帮助我解决这个问题。
发布于 2018-06-22 13:37:27
如果没有,您是否将the_content()放在循环中
在这里试试这个:
if (have_posts()) {
while (have_posts()) {
the_post();
?>
<article class="post">
<h3><?php the_title(); ?></h3>
<p><?php the_content(); ?></p>
</article>
<?php
} // end while
} // end if
?>发布于 2019-02-11 06:23:15
可能是因为在循环之外使用了get_the_excerpt、get_the_content或类似的函数(在自定义上下文中,在主题的functions.php中的某个地方)。
在前面添加setup_postdata。它会填充全局变量$pages。否则,PHP7.2+将在post-template.php的第284行输出一个警告。
例如:
global $post;
setup_postdata($post);
$excerpt = get_the_excerpt($post);发布于 2019-03-01 12:31:55
该问题源于在PHP 7.2+中使用the_content或get_the_content,因为这些函数具有对全局页的检查,该全局页可能为空。在7.2中,null不是countable的有效值,这就是解决这个错误的方法,解决方法是直接从元字段中提取内容。下面的代码,更多信息可以在我制作的https://www.youtube.com/watch?v=vMguTNzFoUk视频中找到(我猜TLDR部分在视频中间,第一个只是片断放置解释)
apply_filters('the_content', get_post_field('post_content', $post->id));https://stackoverflow.com/questions/50759102
复制相似问题