我试图定义WordPress的一个新的短代码,和我当功能被加载以下错误(只装,我还没有试过打电话给它的任何地方尚未):count()导致“意外的T_STRING”错误?
Parse error: syntax error, unexpected T_STRING in /pathtomytheme/user_functions.php on line 105
这里的码;线105为 “$ cat_n =计数($猫) - 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>';
}
如果我改变该行,使得它不使用计数功能,例如到“$ cat_n = 5;”,该函数加载没有错误。似乎我错过了一些非常明显的东西;它是什么?
原始代码是在这里:http://pcsplace.com/blog-tips/how-to-split-categories-list-into-columns-in-wordpress/
+1好点。 PHP将ASCII 226视为一个'单词'字符,因此它不再有效'$ cat_n = count($ cats)hello 1;' – 2009-09-03 23:49:37
谢谢rogeriopvl,你是对的。现在一切顺利。 – Becca 2009-09-04 02:51:42