我创建了一个用于模块(文章类别 NewsFlash)的替代模板。我正在展示三篇文章。三个特定类别中的一个(我有三个以上的类别,但我只想从这三个中显示)。
Newsflash 允许我选择特定的类别来查看 - 所以这不是问题。
我已将模板设置为如下所示:
<?php $images = json_decode($item->images);
$item_heading = $params->get('item_heading', 'h4'); ?>
<a href="<?php echo $item->link;?>">
<img width="130" height="82" src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>" />
</a>
<!--------------------------->
<h1>CHECK THE CATEGORY HERE</h1>
<!--------------------------->
<p class="valign" style="margin-top: 13px;">
<a class="gray" href="/reviews/bikes/kawasaki-adversys-versys-650-project">
<-- The span below changes based on the category -->
<span class="green fs12 db mb5">Latest Bike Review</span>
<?php echo $item->title;?>
</a>
</p>
而且效果很好。它显示三篇文章,水平内联,首先显示介绍图像,然后是一行文本,然后是文章的标题。
我的问题是,如何查看当前文章的类别?上面的代码正在循环中。我假设它是类似的东西,$item->category
但我似乎无法弄清楚或在任何地方找到它。
如果可以的话请帮忙!
更新:
我最终使用了不同的模块mod_articles_category
。使用此模板中的默认值,我将 default.php 更改为以下内容:
<?php
defined('_JEXEC') or die;
?>
<div class="main sub-page" role="main">
<div class="header layout-img">
<p class="fl mt20">
<span class="yellow2 fs18">LATEST</span>
<br>
<span class="white fs14">REVIEWS</span>
</p>
<ul>
<?php
$mediafound = 0;
$gearfound = 0;
$bikefound = 0;
$currentitem = '';
foreach ($list as $item) :
$images = json_decode($item->images);
$item_heading = $params->get('item_heading', 'h4');
if(strpos($item->catslug, 'media') !== FALSE) {
$mediafound = $mediafound + 1;
$currentitem = 'media';
} elseif(strpos($item->catslug, 'gear') !== FALSE) {
$gearfound = $gearfound + 1;
$currentitem = 'gear';
} elseif(strpos($item->catslug, 'bike') !== FALSE) {
$bikefound = $bikefound + 1;
$currentitem = 'bike';
} ?>
<?php if($currentitem == 'media' && $mediafound == 1) { ?>
<li>
<a href="<?php echo $item->link;?>">
<img width="130" height="82" src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>" />
</a>
<h1></h1>
<p class="valign" style="margin-top: 13px;">
<a class="gray" href="/reviews/bikes/kawasaki-adversys-versys-650-project">
<span class="green fs12 db mb5">Latest Media Review</span>
<?php echo $item->title;?>
</a>
</p>
<span class="article-separator"> </span>
</li>
<?php } elseif($currentitem == 'gear' && $gearfound == 1) { ?>
<li>
<a href="<?php echo $item->link;?>">
<img width="130" height="82" src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>" />
</a>
<h1></h1>
<p class="valign" style="margin-top: 13px;">
<a class="gray" href="/reviews/bikes/kawasaki-adversys-versys-650-project">
<span class="green fs12 db mb5">Latest Gear Review</span>
<?php echo $item->title;?>
</a>
</p>
<span class="article-separator"> </span>
</li>
<?php } elseif($currentitem == 'bike' && $bikefound == 1) { ?>
<li>
<a href="<?php echo $item->link;?>">
<img width="130" height="82" src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>" />
</a>
<h1></h1>
<p class="valign" style="margin-top: 13px;">
<a class="gray" href="/reviews/bikes/kawasaki-adversys-versys-650-project">
<span class="green fs12 db mb5">Latest Bike Review</span>
<?php echo $item->title;?>
</a>
</p>
<span class="article-separator"> </span>
</li>
<?php } ?>
<?php endforeach; ?>
</ul>
</div>
</div>
这很好地展示了三个不同类别的最新文章。