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

标签 php css width categories

我正在尝试分配不同的类别 ID 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;
}

最佳答案

你可以这样使用:

$class = 'Meta1';

现在设置其他的:

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

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

在“粗暴”的谈话模式中,这是更简单、更快捷的方式。

您也可以在循环中或其他任何地方改进它。

这主要用于生成“奇数”和“偶数”结果,例如表格和备用 div。

关于php - 为不同的categoryID设置不同的列宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21686364/

相关文章:

php - 在 Zend Framework 应用程序中从模型/ View / Controller 中抛出异常

php - 向mysql表中插入json数据

javascript - 图像淡入然后文本不起作用

android - Android 浏览器中的 CSS 布局

jquery - 如何在jquery中以百分比设置宽度

php - 获取分组依据的查询结果

PHP数组删除字符并只保留数字

css - 获取一个 div 来遍历整个页面

html - css:Chrome 和 Safari 中不同的列容器高度(bootstrap 4)

javascript - 当 "justify"的文本开始推送表格时,我如何 `th` 文本?