How to add the category description/image in the item view ?

More
12 years 6 months ago #19657 by vlester
Hello,

Sorry if it has already been asked but I couldn't find an answer on the forum.
On my item template, the name of the category is displayed but I would like to add the description and the image of the category. Is it possible ?
Thanks for your support

Please Log in or Create an account to join the conversation.

More
12 years 6 months ago #19658 by ggppdk
mmm, the most straightforward way, would be to query the category database table.

So you can enter the following, at the place you like in your item.php file of your template.
Code:
// Get current category OR If current category is not set in the URL, we will use the item's main category $cid = JRequest::getInt('cid', $this->item->catid); // Get category data from DB $db = & JFactory::getDBO(); $query = "SELECT * from #__categories " ." WHERE id='".$cid."'"; $db->setQuery($query); $curcat = $db->loadObject(); // or die($db->getErrorMsg()); // Use category data echo "<span class='flexi_currcat_title_label'>".JText::_('Category Title')."</span>: "; echo "<span class='flexi_currcat_title_value'>".$curcat->title."</span><br>"; echo "<span class='flexi_currcat_descr_label'>".JText::_('Category Description')."</span>: "; echo "<div class='flexi_currcat_descr_value'>"; echo "<img class='flexi_currcat_image_value' src='".JURI::base(true)."/images/stories/".$curcat->image."' title='".$curcat->title."' align='".$curcat->image_position."' />"; echo mb_substr($curcat->title, 0, $maxdescrchars=150); echo "</div>";

Use the css classes to style your output, also you may want to put inside <img ...> a: width='250' instead of using the css class

Regards


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
12 years 6 months ago #19738 by vlester
Thanks a lot, I didn't expect that much !
I just added to your code this line to show the description text :
Code:
echo "<span class='flexi_currcat_title_value'>".$curcat->description."</span><br>";

Please Log in or Create an account to join the conversation.

More
12 years 6 months ago #19739 by ggppdk
Some things are more straightforward to do than others and what you needed was straightforward, and i think your request could be useful to more people, so i am considering adding this to the standard templates

E.g to the category parameters (in its template specific parameters) and then also allow each individual item to override this (again not in its standard parameters but in its template specific parameters)


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.258 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline