为不同的categoryID设置不同的列宽

时间:2014-02-10 19:39:15

标签: php css width categories

我正在尝试分配不同的CategoryID 1,2和3 if ($Category->CategoryID > 0)以使用不同的列宽<div class="Meta1">。如何添加2个CategoryID?感谢。

      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="Meta1">
                 ';
                 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>';
     }
  }

CSS:

.DataList .Meta1 {
width: 60px;
}

.DataList .Meta2 {
width: 80px;
}

.DataList .Meta3 {
width: 100px;
}

1 个答案:

答案 0 :(得分:0)

您可以使用以下内容:

$class = 'Meta1';

现在设置其他人:

if($Category->CategoryID % 2 == 0){
    $class = 'Meta2';
    //do stuff
}

if($Category->CategoryID % 3 == 0){
    $class = 'Meta3';
    //do stuff
}

以“粗暴”的谈话方式,是更容易,更快捷的方式。

您可以循环或其他任何方式改进它。

这主要用于做“奇数”和“偶数”结果,如表和备用div。