donglin1192 2017-04-14 12:06
浏览 56
已采纳

在Joomla中检测类别ID = 4并显示div

I would like to detect a certain category with ID=4 and then apply if/else to add div to display contents.

<?php 
    if (JRequest::getVar('view')=='categories' && JRequest::getVar('id')==4) { ?>
<?php } ?>

How do I achieve this? I want to show this if the article belongs to category 4 else show another div.

Imagining this two be the different div

<div class="category4">text here</div>
<div class="categoryxxx">text here</div>

Do note that <?php echo $this->item->catid;?> shows the correct Category ID. I would like to apply if and else statement using catid==9 or something. Just not good at PHP.

  • 写回答

2条回答 默认 最新

  • dpo60833 2017-04-14 17:41
    关注

    You can also put directly the html code, avoiding echo. It may useful especially when html code is sizeable.

    <?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; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?