在Joomla中检测类别ID = 4并显示div
问题描述:
我想检测ID = 4的某个类别,然后应用if/else将div添加到显示内容。在Joomla中检测类别ID = 4并显示div
<?php
if (JRequest::getVar('view')=='categories' && JRequest::getVar('id')==4) { ?>
<?php } ?>
我该如何做到这一点? 如果文章属于类别4,我想显示它,否则显示另一个div。
想象这个,两个人不同的div
<div class="category4">text here</div>
<div class="categoryxxx">text here</div>
请注意,<?php echo $this->item->catid;?>
显示正确的类别ID。我想申请if和else语句使用catid == 9什么的。只是不擅长PHP。
答
您也可以直接把html代码,避免echo
。当html代码很大时,它可能会很有用。
<?php if ($this->item->catid == 4): ?>
<div class="category4">text here</div>
<!--- any other html code --->
<?php else: ?>
<div class="categoryxxx">text here</div>
<!--- any other html code --->
<?php endif; ?>
答
嘿,我得到它的工作:)
<?php
if ($this->item->catid == 9) {
echo "yes, it exists";
}
else {
echo "no, it don't exist";
}
?>