【发布时间】:2019-10-18 15:48:00
【问题描述】:
在我的网站上,我允许人们上传图片库。当他们点击图片时,底部会出现 下一个 和 上一个 按钮,因此他们可以轻松地在图片中来回滚动。
我在位于 /opt/cpanel/ea-php72/root/usr/var/log/php-fpm/ 的日志中收到以下错误
NOTICE: PHP message: PHP Warning: count(): Parameter must be an array or an object that implements Countable in . . . on line 12
它在我的代码中谈论以下行:
$max = count($photos);
以下是该行附带的其他代码:
$photos = get_field('gallery');
$max = count($photos); <------- error line here -------->
$current = (isset($_GET['image'])) ? intval($_GET['image']) : false;
if ($current !== false) {
if ($current > $max) $current = $max;
if ($current < 1) $current = 1;
}
$next = (($current + 1) < $max) ? ($current + 1) : $max;
$prev = (($current - 1) > 1) ? ($current - 1) : 1;
?>
基本上这段代码使用 get_field('gallery') 来获取图库中的照片总数,并将数量分配给变量 max。
其余的代码是下一个和上一个按钮的工作原理。
我不知道出了什么问题。有人可以帮忙吗?
【问题讨论】:
-
get_field() 是做什么的?
-
嗯,让我看看。它是我正在使用的 Wordpress 主题文件的一部分,所以我不太清楚。让我了解一下
-
请做一些基本的调试。在
count($photos);之前添加var_dump($photos);以查看变量实际包含的内容。它显然不是任何可数类型。此外,get_field()最常与插件“高级自定义字段”一起使用。 -
是的,我现在看到了。我已经安装了 ACF。谢谢。