的這個腳本顯示文章的類別,但不包括用戶不希望顯示的:添加正確的號碼逗號
function exclude_post_categories($excl='', $spacer=' ') {
$categories = get_the_category($post->ID);
if (!empty($categories)) {
$exclude = $excl;
$exclude = explode(",", $exclude);
$thecount = count(get_the_category()) - count($exclude);
foreach ($categories as $cat) {
$html = '';
if (!in_array($cat->cat_ID, $exclude)) {
$html .= '<a href="' . get_category_link($cat->cat_ID) . '" ';
$html .= 'title="' . $cat->cat_name . '">' . $cat->cat_name . '</a>';
if ($thecount > 1) {
$html .= $spacer;
}
$thecount--;
echo $html;
}
}
}
}
的fuctions被觸發這個樣子。
<?php exclude_post_categories('5', ', ');
所以,如果一個職位有1,2,3,4,5的類別,只有1,2,3,4被迴應。
該腳本適用於排除了類別的帖子(5)。
問題在於沒有該類別的帖子。
所以,如果一個職位有三類:1,2,3,4,這些都回蕩但比需要較少的逗號:1,2,34
$ thecount變量始終計算錯誤的職位,沒有必須排除的類別。