2014-02-11 44 views
0

if ($Category->CategoryID > 0)适用于所有类别。如何消除一些的categoryID像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

相反,如果你知道你想你可以使用MySQL IN()函数的类别。 –

回答

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)) 
0

你只需要检查你不想要的数字。

更改此行

if ($Category->CategoryID > 0) { 

对此

if ($Category->CategoryID != 1) { 

将意味着你没有得到类别1.

要删除几个类别使用。

if ($Category->CategoryID != 1 && $Category->CategoryID != 2) { 

您可以无限期地继续此操作。但正如Abhishek kadadi在使用MySQL的评论中所建议的,也可能是一个解决方案。

但是很明显,如果您添加任何其他类别,您将需要硬编码它,如果它不被看到。

可能你可以在数据库中添加另一个字段,即。可见,那些可见的将显示等等。然后,你可以做一个MySQL查询只可见的,只需添加一个新的类别和可见性将是所有必要的。

0

考虑过滤器类别中的SQL语句,就像这样:

SELECT * FROM table_name WHERE field_name NOT IN (1,2,3)