Count () causing an "unexpected T_STRING" error?

I am trying to define a new shortcode in WordPress, and I get the following error when loading a function (just loaded, I have not tried to name it yet):

Parse error: syntax error, unexpected T_STRING in /pathtomytheme/user_functions.php on line 105

Here is the code; line 105 - "$ cat_n = count ($ cats) - 1;":

function usertag_2colcats($atts) {
extract(shortcode_atts(array('parent' => 0,'depth' => 2,), $atts));
$cats = explode('<br />', wp_list_categories('title_li=&echo=0&depth=' . $depth . '&style=none&show_count=1&use_desc_for_title=0&child_of=' . $parent));
$cat_n = count($cats) – 1;
for ($i = 0; $i < $cat_n; $i++) {
    if ($i < $cat_n/2) $cat_left = $cat_left . '<li>' . $cats[$i] . '</li>';
    elseif ($i >= $cat_n/2) $cat_right = $cat_right.'<li>'.$cats[$i].'</li>';
}
echo '<ul class="leftcats">' . $cat_left . '</ul><ul class="rightcats">' . $cat_right . '</ul>';

}

If I change this line so that it does not use the count function, for example. to "$ cat_n = 5;", the function loads without errors. I seem to be missing something really obvious; what is it?

The original code is here: http://pcsplace.com/blog-tips/how-to-split-categories-list-into-columns-in-wordpress/

+3
source share
2 answers

, "-" 105 . , . , .

: , . , 105, ASCII 226. ASCII 45. .

;)

+4

var_dump( $cats )?

count() false , , , .

+1

Source: https://habr.com/ru/post/1716854/


All Articles