【问题标题】:Joomla v3 multiple PHP IF's in one statementJoomla v3 多个 PHP IF 在一个语句中
【发布时间】:2014-05-20 10:49:20
【问题描述】:

在 Joomla v3 中,我想做以下事情:

'countModules' 用下面的模块,查看是否分配了一个模块:

<?php if ($this->countModules('right')) : ?>

但我也只想在文章页面上显示模块位置,而不是使用下面的类别博客页面:

<?php if( JRequest::getVar( 'view' ) == 'article' ): ?>

如何将上述两个 IF 放入以下语句的 1 条语句中,以便模块位置不显示并且 div 仅在类别博客页面上被删除(但显示在文章页面上):

<section class="sidebar right-sidebar">
   <jdoc:include type="modules" name="right" style="standard" />
</section>

【问题讨论】:

  • &amp;&amp; 他们之间? if ($foo &amp;&amp; $bar)?这与 Joomla 无关——它完全是基本的 PHP?
  • 请不要在 Joomla 3.x 中使用 JRequest,因为它已被弃用
  • 可能是 Joomla 的东西......但以下不起作用: countModules('right')) && ( JRequest::getVar( 'view ' ) == '文章' )): ?>
  • @user3544484 那是因为其中之一是false 或假的。使用var_dump($this-&gt;countModules('right'), JRequest::getVar('view')) 找出原因。
  • 是的......我期望在那里的一切......

标签: php if-statement joomla joomla3.0


【解决方案1】:

这是你要找的吗?

<?php
   $jinput = JFactory::getApplication()->input;
   $view = $jinput->get('view');

   if($view == 'article' && $this->countModules('right')) {
   ?>
      <section class="sidebar right-sidebar">
          <jdoc:include type="modules" name="right" style="standard" />
      </section>
   <?php
   }
?>

还删除了您正在使用的旧的已弃用的 JRequest 并改为使用 JApplication

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-28
    • 1970-01-01
    • 1970-01-01
    • 2020-07-23
    相关资源
    最近更新 更多