如果未选择任何特色图像,请更改html引导标记

时间:2016-06-02 14:09:42

标签: php html twitter-bootstrap-3 joomla joomla3.0

我有一个基于Protostar模板的自定义Joomla 3引导程序模板。

目前左侧主要内容区域标记为:

<div class="itemMainContent col-sm-8 col-xs-12">

如果未设置/激活特色图像,则左侧主要内容标记的方式是:

<div class="itemMainContent col-xs-12">

基本如果没有设置右侧边栏/特色图像,主要内容区域应为全宽(12列)。

摘自主内容区域的default.php标记和右侧特色图像侧边栏如下:

<div class="itemMainContent col-sm-8 col-xs-12">
  <?php
    if (!empty($this->item->pagination) && $this->item->pagination && !$this->item->paginationposition && !$this->item->paginationrelative):
        echo $this->item->pagination;
    endif;
    ?>
    <?php if (isset ($this->item->toc)) :
        echo $this->item->toc;
    endif; ?>
      <?php echo $this->item->text; ?>

        <?php if ($useDefList && ($info == 1 || $info == 2)) : ?>
          <div class="article-info muted">
            <dl class="article-info">
              <dt class="article-info-term"><?php echo JText::_('COM_CONTENT_ARTICLE_INFO'); ?></dt>

              <?php if ($info == 1) : ?>
                <?php if ($params->get('show_author') && !empty($this->item->author )) : ?>
                  <dd class="createdby">
                    <?php $author = $this->item->created_by_alias ? $this->item->created_by_alias : $this->item->author; ?>
                      <?php if (!empty($this->item->contactid) && $params->get('link_author') == true) : ?>
                        <?php
                        $needle = 'index.php?option=com_contact&view=contact&id=' . $this->item->contactid;
                        $menu = JFactory::getApplication()->getMenu();
                        $item = $menu->getItems('link', $needle, true);
                        $cntlink = !empty($item) ? $needle . '&Itemid=' . $item->id : $needle;
                        ?>
                          <?php echo JText::sprintf('COM_CONTENT_WRITTEN_BY', JHtml::_('link', JRoute::_($cntlink), $author)); ?>
                            <?php else: ?>
                              <?php echo JText::sprintf('COM_CONTENT_WRITTEN_BY', $author); ?>
                                <?php endif; ?>
                  </dd>
                  <?php endif; ?>
                    <?php if ($params->get('show_parent_category') && !empty($this->item->parent_slug)) : ?>
                      <dd class="parent-category-name">
                        <?php   $title = $this->escape($this->item->parent_title);
                        $url = '<a href="' . JRoute::_(ContentHelperRoute::getCategoryRoute($this->item->parent_slug)) . '">' . $title . '</a>';?>
                          <?php if ($params->get('link_parent_category') && $this->item->parent_slug) : ?>
                            <?php echo JText::sprintf('COM_CONTENT_PARENT', $url); ?>
                              <?php else : ?>
                                <?php echo JText::sprintf('COM_CONTENT_PARENT', $title); ?>
                                  <?php endif; ?>
                      </dd>
                      <?php endif; ?>
                        <?php if ($params->get('show_category')) : ?>
                          <dd class="category-name">
                            <?php   $title = $this->escape($this->item->category_title);
                        $url = '<a href="' . JRoute::_(ContentHelperRoute::getCategoryRoute($this->item->catslug)) . '">' . $title . '</a>';?>
                              <?php if ($params->get('link_category') && $this->item->catslug) : ?>
                                <?php echo JText::sprintf('COM_CONTENT_CATEGORY', $url); ?>
                                  <?php else : ?>
                                    <?php echo JText::sprintf('COM_CONTENT_CATEGORY', $title); ?>
                                      <?php endif; ?>
                          </dd>
                          <?php endif; ?>
                            <?php if ($params->get('show_publish_date')) : ?>
                              <dd class="published">
                                <span class="icon-calendar"></span>
                                <?php echo JText::sprintf('COM_CONTENT_PUBLISHED_DATE_ON', JHtml::_('date', $this->item->publish_up, JText::_('DATE_FORMAT_LC3'))); ?>
                              </dd>
                              <?php endif; ?>
                                <?php endif; ?>

                                  <?php if ($params->get('show_create_date')) : ?>
                                    <dd class="create">
                                      <span class="icon-calendar"></span>
                                      <?php echo JText::sprintf('COM_CONTENT_CREATED_DATE_ON', JHtml::_('date', $this->item->modified, JText::_('DATE_FORMAT_LC3'))); ?>
                                    </dd>
                                    <?php endif; ?>
                                      <?php if ($params->get('show_modify_date')) : ?>
                                        <dd class="modified">
                                          <span class="icon-calendar"></span>
                                          <?php echo JText::sprintf('COM_CONTENT_LAST_UPDATED', JHtml::_('date', $this->item->modified, JText::_('DATE_FORMAT_LC3'))); ?>
                                        </dd>
                                        <?php endif; ?>
                                          <?php if ($params->get('show_hits')) : ?>
                                            <dd class="hits">
                                              <span class="icon-eye-open"></span>
                                              <?php echo JText::sprintf('COM_CONTENT_ARTICLE_HITS', $this->item->hits); ?>
                                            </dd>
                                            <?php endif; ?>
            </dl>
          </div>
          <?php endif; ?>

            <?php
if (!empty($this->item->pagination) && $this->item->pagination && $this->item->paginationposition && !$this->item->paginationrelative):
    echo $this->item->pagination;
?>
              <?php endif; ?>
                <?php if (isset($urls) && ((!empty($urls->urls_position) && ($urls->urls_position == '1')) || ($params->get('urls_position') == '1'))) : ?>
                  <?php echo $this->loadTemplate('links'); ?>
                    <?php endif; ?>
                      <?php // Optional teaser intro text for guests ?>
                        <?php elseif ($params->get('show_noauth') == true && $user->get('guest')) : ?>
                          <?php echo $this->item->introtext; ?>
                            <?php //Optional link to let them register to see the whole article. ?>
                              <?php if ($params->get('show_readmore') && $this->item->fulltext != null) :
        $link1 = JRoute::_('index.php?option=com_users&view=login');
        $link = new JURI($link1);?>
                                <p class="readmore">
                                  <a href="<?php echo $link; ?>">
                                    <?php $attribs = json_decode($this->item->attribs); ?>
                                      <?php
        if ($attribs->alternative_readmore == null) :
            echo JText::_('COM_CONTENT_REGISTER_TO_READ_MORE');
        elseif ($readmore = $this->item->alternative_readmore) :
            echo $readmore;
            if ($params->get('show_readmore_title', 0) != 0) :
                echo JHtml::_('string.truncate', ($this->item->title), $params->get('readmore_limit'));
            endif;
        elseif ($params->get('show_readmore_title', 0) == 0) :
            echo JText::sprintf('COM_CONTENT_READ_MORE_TITLE');
        else :
            echo JText::_('COM_CONTENT_READ_MORE');
            echo JHtml::_('string.truncate', ($this->item->title), $params->get('readmore_limit'));
        endif; ?>
                                  </a>
                                </p>
                                <?php endif; ?>
                                  <?php endif; ?>
                                    <?php
if (!empty($this->item->pagination) && $this->item->pagination && $this->item->paginationposition && $this->item->paginationrelative) :
    echo $this->item->pagination;
?>
                                      <?php endif; ?>
                                        <?php echo $this->item->event->afterDisplayContent; ?>
</div>
<!--- /itemMainContent --->


<!-- sidebar -->
<?php if ($params->get('access-view')):?>
  <?php if (isset($images->image_fulltext) && !empty($images->image_fulltext)) : ?>
    <?php $imgfloat = (empty($images->float_fulltext)) ? $params->get('float_fulltext') : $images->float_fulltext; ?>
      <div class="pull-<?php echo htmlspecialchars($imgfloat); ?> item-image col-sm-4 col-xs-12"> <img <?php if ($images->image_fulltext_caption): echo 'class="caption"'.' title="' .htmlspecialchars($images->image_fulltext_caption) . '"'; endif; ?> src="
        <?php echo htmlspecialchars($images->image_fulltext); ?>" alt="
          <?php echo htmlspecialchars($images->image_fulltext_alt); ?>"/> </div>
      <?php endif; ?>
        <?php endif; ?>
          <!-- /sidebar -->
          </div>

以下是网站本身http://dev.shareandcare.org/empoweringruralindia/signature-programs/educate-2-success-e2s

1 个答案:

答案 0 :(得分:0)

图片似乎包含在$images->image_fulltext中,因此您可以使用empty查看该图片是否存在。

如果图像存在,则仅打印班级名称col-sm-8

<div class="itemMainContent <?php if (!empty($images->image_fulltext)) echo "col-sm-8" ?> col-xs-12">

对不起,我对Joomla并不熟悉,所以我很好奇如何填充$image变量。考虑到我的解决方案发布在您发布的代码的开头,$image变量可能尚未可用。在这种情况下,您需要先获得它。我怀疑地看着侧栏$params->get('access-view')的第一行。您可能需要先调用它。我希望以后可以再次打电话,但你可能不得不玩它,或者有经验的人可能会参与其中。