[英]Detect Category ID=4 in Joomla and show div
我想检测ID = 4的某个类别,然后应用if / else添加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。 我想应用catid == 9之类的if和else语句。 只是不擅长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";
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.