[英]wordpress functions.php
我在带有变量的functions.php文件中遇到问题
$prev_dept = 0;
$comment_count = 0;
$comment_index = 0;
function setCommentCount($size){
$comment_count = $size;
}
function flowhub_comment($comment, $args, $depth) {
$comment_index ++;
if($depth > 1) {
$line = true;
}
echo '$prev_dept:' . $prev_dept.'<br>';
}
我无法访问$ comment_index,因此无法在函数中进行设置或获取。 我应该怎么做才能解决这个问题?
诚实地
$comment_index
不在函数范围内,您需要使用global
。 有关PHP作用域的更多详细信息 。
functions.php的工作方式不仅包含在内,尝试使用GLOBAL可能会有所帮助。
function setCommentCount($size){
global $comment_count;
$comment_count = $size;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.