我試圖定義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