- Installation
- Configuration
- Frontend modules
- Template adjustments
- News feeds
- Multilingual features
- Insert tags
You can display the categories in your custom news_
templates. See the different possibilities below.
All the categories data is added to every news partial template which allows you to render any HTML markup
of the categories you can imagine. The categories are available in the $this->categories
variable.
Pro tip: access the news category model directly via $category['model']
.
Example:
<?php if ($this->categories): ?>
<ul class="categories">
<?php foreach ($this->categories as $category): ?>
<li class="<?= $category['class'] ?>">
<?php if ($category['image']): ?>
<figure class="image_container">
<?php $this->insert('picture_default', $category['image']->picture) ?>
</figure>
<?php endif; ?>
<?php if ($category['href']): ?>
<a href="<?= $category['href'] ?>" title="<?= $category['linkTitle'] ?>"><?= $category['name'] ?></a>
<?php else: ?>
<span><?= $category['name'] ?></span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
To display a simple, plain-text category list you can use the array of $this->categoriesList
:
<p class="categories">Categories: <?= implode(', ', $this->categoriesList) ?></p>
Example output markup:
<p class="categories">Categories: Music, Sport</p>
The categories list module is similar to the navigation module. It also uses the two templates to render the markup:
mod_newscategories
– the "wrapper" for the category navigation treenav_newscategories
– the partial template used to generate the navigation items recursively
Both of the templates can be overwritten in the frontend module settings.