Aram Aram - 1 year ago 188
PHP Question

Joomla 3: adding category-image in article template

I'm overriding the article template of my Joomla 3 website which is

. I need to add the category image into my article template.
I already tried:

$db = &JFactory::getDBO();
$id = JRequest::getString('id');
$db->setQuery('SELECT #__categories.params FROM #__content, #__categories WHERE #__content.catid = AND = '. $db->quote($id));
$category = $db->loadResult();
echo $category;

The result is something like:


But how do I extract only the image from this JSON string?

Answer Source

You have to decode the string. Try PHP's json_decode. Add to your code:


$category = json_decode($category);
echo $category->image;


$category = json_decode($category, true);
echo $category['image'];

You can also do this natively in Joomla with something like this:

$category = JCategories::getInstance('Content')->get($id);
echo $category->getParams()->get('image');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download