【问题标题】:Detect Category ID=4 in Joomla and show div在 Joomla 中检测类别 ID=4 并显示 div
【发布时间】:2017-09-10 16:39:08
【问题描述】:

我想检测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>

请注意&lt;?php echo $this-&gt;item-&gt;catid;?&gt; 显示正确的类别 ID。我想使用 catid==9 或其他东西来应用 if 和 else 语句。只是不擅长 PHP。

【问题讨论】:

    标签: php joomla joomla2.5 joomla3.0


    【解决方案1】:

    也可以直接放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; ?>
    

    【讨论】:

      【解决方案2】:

      嘿,我搞定了 :)

      <?php
      if ($this->item->catid == 9) { 
          echo "yes, it exists"; 
          } 
          else { 
          echo "no, it don't exist"; 
          }
      ?>
      

      【讨论】:

        猜你喜欢
        • 2014-02-14
        • 1970-01-01
        • 1970-01-01
        • 2014-03-04
        • 2013-03-16
        • 1970-01-01
        • 2012-03-08
        • 2023-03-16
        • 1970-01-01
        相关资源
        最近更新 更多