此if ($Category->CategoryID > 0)
适用于所有类别。如何消除一些类别ID,如1,2和3.
if ($Category->CategoryID > 0) {
// If we are below the max depth, and there are some child categories
// in the $ChildCategories variable, do the replacement.
if ($Category->Depth < $MaxDisplayDepth && $ChildCategories != '') {
$CatList = str_replace('{ChildCategories}', '<span class="ChildCategories">'.Wrap(T('Child Categories:'), 'b').' '.$ChildCategories.'</span>', $CatList);
$ChildCategories = '';
}
if ($Category->Depth >= $MaxDisplayDepth && $MaxDisplayDepth > 0) {
if ($ChildCategories != '')
$ChildCategories .= ', ';
$ChildCategories .= Anchor(Gdn_Format::Text($Category->Name), '/categories/'.$Category->UrlCode);
} else if (($DoHeading || $DoHeadings) && $Category->Depth == 1) {
$CatList .= '<li class="Item CategoryHeading Title Info Depth1 Category-'.$Category->UrlCode.' '.$CssClasses.'">
<div class="ItemContent Category">'.Anchor(Gdn_Format::Text($Category->Name), '/categories/'.$Category->UrlCode).'</div>'
.GetOptions($Category, $this).'
</li>';
$Alt = FALSE;
} else {
$LastComment = UserBuilder($Category, 'LastComment');
$AltCss = $Alt ? ' Alt' : '';
$Alt = !$Alt;
$CatList .= '<li class="'.$Category->Depth.$AltCss.' Category-'.$Category->UrlCode.' '.$CssClasses.'">
<div class="SubMenu1 Category '.$CssClasses.'">'
.Anchor(Gdn_Format::Text($Category->Name), '/categories/'.$Category->UrlCode, 'Title')
.GetOptions($Category, $this)
.Wrap($Category->Description, 'div', array('class' => 'CategoryDescription'))
.'<div class="Meta2">
';
if ($Category->LastCommentID != '' && $Category->LastDiscussionTitle != '') {
$CatList .= '<span class="LastDiscussionTitle">'.sprintf(
T('Most recent: %1$s by %2$s'),
Anchor(SliceString($Category->LastDiscussionTitle, 40), '/discussion/'.$Category->LastDiscussionID.'/'.Gdn_Format::Url($Category->LastDiscussionTitle)),
UserAnchor($LastComment)
).'</span>'
.'<span class="LastCommentDate">'.Gdn_Format::Date($Category->DateLastComment).'</span>';
}
$CatList .= '</div>
</div>
</li>';
}
}
答案 0 :(得分:0)
如果您特别不想要类别1,2和3(非常有限的解决方案):
if ($Category->CategoryID > 3)
或者,如果您知道哪些类别不需要:
if (!in_array($Category->CategoryID, array(1, 2, 3)))
或者,如果您要在代码中找出之前不想要的类别:
$bad_categories = array();
//populate $bad_categories to fit your needs...
if (!in_array($Category->CategoryID, $bad_categories))
答案 1 :(得分:0)
您只需要检查您不想要的数字。
更改此行
if ($Category->CategoryID > 0) {
到此
if ($Category->CategoryID != 1) {
意味着你没有获得第1类。
要删除几个类别,请使用此功能。
if ($Category->CategoryID != 1 && $Category->CategoryID != 2) {
您可以无限期地继续这样做。但正如Abhishek kadadi在评论中建议使用MySQL也可能是一个解决方案。
但是很明显,如果你添加任何其他类别,如果不能看到它,你需要对其进行硬编码。
您可以在数据库中添加另一个字段,即。可见,那些可见的将被显示等。然后你可以只查看可见的MySQL查询,只需添加一个新的类别和可见性将是所有必要的。
答案 2 :(得分:0)
考虑SQL语句中的过滤器类别,如下所示:
SELECT * FROM table_name WHERE field_name NOT IN (1,2,3)