post-template的PHP7.2报错

最近这两个月网站收录大幅度下降,各大搜索引擎搜索结果报错,仔细一看,是『description』文章描述报错。

报错内容为:Warning: count(): Parameter must be an array or an object that implements Countable in /wp-includes/post-template.php on line 284

后台查询是wordpress根目录/wp-includes/post-template.php的第284行报错。

一番谷歌后,发现是wordpress对php7.2的兼容性问题,找到了解决办法

复制下面内容并进行替换保存既可解决问题:

if ( is_array( $pages ) ) {
if ( $page > count( $pages ) ) // if the requested page doesn't exist
$page = count( $pages ); // give them the highest numbered page that DOES exist
} else {
$page = 0;
}

4