开发者

wordpress functions.php

开发者 https://www.devze.com 2022-12-26 13:28 出处:网络
I\'m having issues with the functions.php file with variables $prev_dept = 0; $comment_count = 0; $comment_index = 0;

I'm having issues with the functions.php file with variables

        $prev_dept = 0;
        $comment_count = 0;
        $comment_index = 0;
        functio开发者_C百科n setCommentCount($size){
            $comment_count = $size;
        }        
        function flowhub_comment($comment, $args, $depth) {
            $comment_index ++;            

            if($depth > 1) {
                $line = true;
            }
            echo '$prev_dept:' . $prev_dept.'<br>';
        }

I can't access $comment_index so I can't set nor get it from within a function. What should I do to fix this?

Yours truthfully


$comment_index is not within the scope of the functions, you need to use global. More details on scoping in PHP.


The way functions.php works is not just a plain include, try GLOBAL it might help.

function setCommentCount($size){
    global $comment_count;
    $comment_count = $size;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号