2014-02-11 46 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)