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