Reputation:
How can I add category description to Article Category modules in Joomla?
The only php call after grouping items is <?php echo $group_name; ?>
.
Thanks in advance!
Upvotes: 0
Views: 2152
Reputation: 292
So in: /modules/mod_articles_category/default.php
make sure you create an over ride first, but then add:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select(array('id', 'title', 'description'));
$query->from($db->quoteName('#__categories'));
$query->where($db->quoteName('extension') . ' = ' . $db->quote('com_content'));
$db->setQuery($query);
$categories = $db->loadObjectList('id');
just after: defined('_JEXEC') or die;
Then in each item you can load it in like:
echo $categories[$item->catid]->description;
If using on the grouping rather than item, it's a little different and here is the whole top snippet replacement:
<?php
/**
* @package Joomla.Site
* @subpackage mod_articles_category
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select(array('id', 'title', 'description'));
$query->from($db->quoteName('#__categories'));
$query->where($db->quoteName('extension') . ' = ' . $db->quote('com_content'));
$db->setQuery($query);
$categories = $db->loadObjectList('title');
?>
<ul class="category-module<?php echo $moduleclass_sfx; ?> mod-list">
<?php if ($grouped) : ?>
<?php foreach ($list as $group_name => $group) : ?>
<li>
<div class="mod-articles-category-group"><?php echo JText::_($group_name); ?></div>
<p><?php echo count($group) > 0 ? $categories[$group_name]->description : ''; ?></p>
Because $group doesn't contain anything but the list, we get the name instead this time and load the categories from the name.
Upvotes: 0
Reputation: 41
I know this is an old post, but for Joomla! 3.5 and higher you can use...
$category = JCategories::getInstance('Content')->get($item->catid);
Much easier than doing a call to the database in your template override files.
Upvotes: 4
Reputation: 76
Put in your default.php override or custom template:
<?php // tested in Joomla 3.1.5 only
$input = JFactory::getApplication()->input;
$idbase = $params->get('catid');
$catID = $idbase[0];
//echo $catID;
$db = JFactory::getDBO();
$db->setQuery("SELECT description FROM #__categories WHERE id = ".$catID." LIMIT 1;");
$catDesc = $db->loadResult();
?>
<div class="catdesc">
<?php echo $catDesc; ?>
</div>
Modified from: http://www.noxidsoft.com/development/get-the-category-blog-description-in-joomla-3-1-5/
Upvotes: 0
Reputation: 1
Add this to your default.php override.
<?php
$db = &JFactory::getDBO();
$id = JRequest::getString('id');
$db->setQuery('SELECT #__categories.description FROM #__content, #__categories WHERE #__content.catid = #__categories.id AND #__content.id = '.$id);
$category = $db->loadResult();
echo $category;
?>
Upvotes: 0