【问题标题】:Joomla how to make the link to category workJoomla如何使到类别的链接起作用
【发布时间】:2012-11-24 11:07:03
【问题描述】:

我在 mytemplate/html/com_content/featured/default.php 中有以下代码

<?php if (!empty($this->lead_items)) : ?>
    <div class="<?php echo $this->pageclass_sfx;?>">
<div class="block-head">
        <h2><?php echo $this->escape($this->params->get('page_heading')); ?></h2>
        <a href="<?php echo JRoute::_(ContentHelperRoute::getCategoryRoute($this->item->catslug)); ?>" class="more">all news</a>
    </div><!-- .block-head -->
<?php foreach ($this->lead_items as &$item) : ?>
    <dl>
        <dt>
        <?php 
            $params = JComponentHelper::getParams( 'com_content' );
            $this->item = &$item;
            $images = json_decode($item->images);
        ?>  
        <?php  if (isset($images->image_intro) and !empty($images->image_intro)) : ?>
            <?php $imgfloat = (empty($images->float_intro)) ? $params->get('float_intro') : $images->float_intro; ?>
                    <a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>" class="img-intro-<?php echo htmlspecialchars($imgfloat); ?>">
                    <img <?php if ($images->image_intro_caption):
                    echo 'class="caption"'.' title="' .htmlspecialchars($images->image_intro_caption) .'"';
                endif; ?>
                src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/>
            </a>
        <?php endif; ?>
        </dt>
        <dd>
            <var class="date"><?php echo JHtml::_('date', $this->item->publish_up, JText::_('DATE_FORMAT_LC')); ?></var>
            <h3><a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>" class="<?php if($this->params->get('page_heading') == 'projects'){echo 'more';}; ?>"><?php echo $this->item->title; ?></a></h3>
            <?php echo $this->item->introtext; ?>
            <div class="news-link clearfix">
                <a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>" class="more"><?php  echo JText::sprintf('COM_CONTENT_READ_MORE_TITLE'); ?></a>
                <div class="line"></div>
            </div>
        </dd>
    <?php
        $leadingcount++;
    ?>
    </dl>
<?php endforeach; ?>

一切正常,除了类别新闻的链接。这里是:

<a href="<?php echo JRoute::_(ContentHelperRoute::getCategoryRoute($this->item->catslug)); ?>" class="more">all news</a>

如何让它发挥作用?

谢谢。


感谢洛德的帮助。我使用了你的代码,只是添加了中断

<div class="block-head">
    <h2><?php echo $this->escape($this->params->get('page_heading')); ?></h2>
    <?php foreach ($this->lead_items as &$item) :
          $this->item = &$item;
          $title = $this->escape($this->item->category_title);
          echo '<a href="'.JRoute::_(ContentHelperRoute::getCategoryRoute($this->item->catid, $this->item->catid)).'" class="more">all '.$title.'</a>';
          break;
     endforeach; ?>
</div><!-- .block-head -->

【问题讨论】:

    标签: php joomla content-management-system joomla2.5


    【解决方案1】:

    完整的解决方案

    <div class="block-head">
        <h2><?php echo $this->escape($this->params->get('page_heading')); ?></h2>
        <?php foreach ($this->lead_items as &$item) :
              $this->item = &$item;
              $title = $this->escape($this->item->category_title);
              echo '<a href="'.JRoute::_(ContentHelperRoute::getCategoryRoute($this->item->catid, $this->item->catid)).'" class="more">all '.$title.'</a>';
              break;
         endforeach; ?>
    </div>
    <?php foreach ($this->lead_items as &$item) : ?>
        <dl>
            <dt>
            <?php 
                $params = JComponentHelper::getParams( 'com_content' );
                $this->item = &$item;
                $images = json_decode($item->images);
            ?>  
            <?php  if (isset($images->image_intro) and !empty($images->image_intro)) : ?>
                <?php $imgfloat = (empty($images->float_intro)) ? $params->get('float_intro') : $images->float_intro; ?>
                        <a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>" class="img-intro-<?php echo htmlspecialchars($imgfloat); ?>">
                        <img <?php if ($images->image_intro_caption):
                        echo 'class="caption"'.' title="' .htmlspecialchars($images->image_intro_caption) .'"';
                    endif; ?>
                    src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/>
                </a>
            <?php endif; ?>
            </dt>
            <dd>
                <var class="date"><?php echo JHtml::_('date', $this->item->publish_up, JText::_('DATE_FORMAT_LC')); ?></var>
                <h3><a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>" class="<?php if($this->params->get('page_heading') == 'projects'){echo 'more';}; ?>"><?php echo $this->item->title; ?></a></h3>
                <?php echo $this->item->introtext; ?>
                <div class="news-link clearfix">
                    <a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>" class="more"><?php  echo JText::sprintf('COM_CONTENT_READ_MORE_TITLE'); ?></a>
                    <div class="line"></div>
                </div>
            </dd>
        <?php
            $leadingcount++;
        ?>
        </dl>
    <?php endforeach; ?>
    

    【讨论】:

      【解决方案2】:

      我唯一能做到的就是这样:

      <div class="block-head">
          <h2><?php echo $this->escape($this->params->get('page_heading')); ?></h2>
          <?php foreach ($this->lead_items as &$item) :
                    $this->item = &$item;
                    echo '<a href="'.JRoute::_(ContentHelperRoute::getCategoryRoute($this->item->catid, $this->item->catid)).'">all news</a>';
                 endforeach; ?>
      </div><!-- .block-head -->
      

      它必须包含在foreach 语句中,并在它之前包含$this-&gt;item = &amp;$item;

      【讨论】:

      • 问题是只需要一个链接。
      • 在这种情况下,你能不能像这样在使用 somtehin 时添加链接:&lt;a href="index.php/rest/of/link"&gt;all news&lt;/a&gt;。如果只需要 1 个链接,则不需要 ContentHelperRoute 内容。
      • 好吧,我不喜欢使用绝对路径。谢谢您的帮助。像往常一样,这是一个很好的答案。我做到了,增加了休息时间;完整代码在我的帖子中
      猜你喜欢
      • 2013-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多