[英]Joomla how to make the link to category work
I have the following code inside mytemplate/html/com_content/featured/default.php 我在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; ?>
All works fine, except the link to category news. 一切正常,除了类别新闻的链接。 Here it is: 这里是:
<a href="<?php echo JRoute::_(ContentHelperRoute::getCategoryRoute($this->item->catslug)); ?>" class="more">all news</a>
How to make it work? 如何使它工作?
Thank you. 谢谢。
Thank you Lodder for your help. 谢谢Lodder的帮助。 I used your code, just added break to it 我使用了你的代码,只是添加了break
<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 -->
The only was I was able to do it was like this: 唯一能让我这样做的是这样的:
<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 -->
It has to be includes inside the foreach
statement and contain $this->item = &$item;
它必须包含在foreach
语句中并包含$this->item = &$item;
before it. 在它之前。
Complete Solution 完整解决方案
<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; ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.