I've been trying to display the category name after the contents of the 'Latest' module in Joomla.
I've made the query in phpMyAdmin and it works. But when I try to use this in the php module template page the page stops at the point the php should start.
$db = &JFactory::getDBO();
$id = JRequest::getString('id');
$db->setQuery("SELECT `title` FROM `#__categories` WHERE `id` = " .$item->catid);
$category = $db->loadResult();
echo $category;
When I replace $item->catid with a fixed number, it works like it does in phpMyAdmin. Can anyone tell me where I go wrong?
Thanks
$item is already having the category title so no need to get it through a db query. You can simply do this in your tmpl file. You can get the category using $item->category_title
<ul class="latestnews<?php echo $moduleclass_sfx; ?>">
<?php foreach ($list as $item) : ?>
<li itemscope itemtype="http://schema.org/Article">
<a href="<?php echo $item->link; ?>" itemprop="url">
<span itemprop="name">
<?php echo $item->title; ?>-
<b><?php echo $item->category_title; ?></b>
</span>
</a>
</li>
<?php endforeach; ?>
</ul>
UPDATE: if you want to display as you asked in comments then you need to do this
<ul class="latestnews<?php echo $moduleclass_sfx; ?>">
<?php foreach ($list as $item) : ?>
<li itemscope itemtype="http://schema.org/Article">
<a href="<?php echo $item->link; ?>" itemprop="url">
<span itemprop="name">
<?php echo $item->title; ?>
</span>
</a>
</li>
<?php endforeach; ?>
<b><a href="<?php JRoute::_("index.php?option=com_content&view=category&layout=$item->category_title&id=$item->catid"); ?>">Click here for more news on ("<?php echo $item->category_title; ?>")</a></b>
</ul>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.