Page 1 of 1
[solved] show full categoryname
Posted: Fri Apr 15, 2011 2:22 pm
by deneddie
Hi,
I'm having a page with many newsitems in different categories and subcategories.
Something like:
- News
-- News | sub1
--- News | sub1 | 1a
--- News | sub1 | 1b
-- News | sub2
-- News | sub3
- Help
-- Help | item1
-- Help | item1 | 1a
...
Depending on the page I show only the category belonging to it and it's subcategories. If the page is not from a certain type I show the last 3 newsitems as a teaser.
When news is shown (in detail or as summary) the category is only the last sub, not the fullname. I want to show te full path, so in stead of seeing 1a as categroy I want to show the user:
News | sub1 | 1a or Help | item1 | 1a.
Can somebody help me with this?
Re: show full categoryname
Posted: Sat Apr 16, 2011 10:24 pm
by spcherub
Here is a quick fix that may or may not work for the version of the News module that you have installed. I have tested this in version 2.11.1 and it works fine.
Create the following UDT (or something similar based on the general idea)
Code: Select all
global $gCms;
$db = &$gCms->db;
$short_name = isset($params['category']) ? $params['category'] : '';
$long_name = $short_name;
if( $short_name != '' ) {
$q1 = 'select long_name from cms_module_news_categories where news_category_name = ?';
$dbr1 = $db->Execute( $q1, array($short_name) );
while ($dbr1 && $row1 = $dbr1->FetchRow()) {
$long_name = $row1['long_name'];
}
}
print $long_name;
Assuming you called this UDT "get_category_path", use the following call in the News detail/summary template:
Code: Select all
{get category_path category=$entry->category}
This should print the full hierarchy of the category of the current news article. The UDT above takes advantage of the "long_name" field that exists in my version of the News module's support table. If this field does not exist in your version of the cms_module_news_categories table, you will need to update UDT to include a recursive call based on the parent_id field and build the full category hierarchy path that way.
Also you can always edit the UDT to return the "long_name" in a smarty variable instead of having it print it out directly. This way you can parse this in your template outside the UDT and style it differently.
It is unfortunate that this value (long_name) exists in the database but is not being exposed in the $entry object in such a way it can be used in the News template without the UDT. Perhaps some one more knowledgeable than I can tell us of way to avoid using the UDT.
Hope this helps.
-S
Re: show full categoryname
Posted: Sun Apr 17, 2011 3:16 pm
by deneddie
spcherub,
Hmm, I'm working with one of the latest version of CMSMS and I know that the long_name field exists in my menu-module.
I'm just a newbie, so can you tell me what you mean with UDT?
It would be nice indeed if someone can tell me how to expose the long_name in the $entry object. I don't think it will be that difficult, but as a newbie, I'm not starting to mess in these files before I have a good understanding of them.
Re: show full categoryname
Posted: Sun Apr 17, 2011 3:48 pm
by deneddie
Ok,
Thans spcherug. Apparently your quick solution works. Figured out that UDT means User Defined Tag, by reading an other forum. All these abbreviations, you don't know what is what after a while.
Re: [solved] show full categoryname
Posted: Mon Apr 18, 2011 11:27 am
by spcherub
@deneddle - sorry I did not expand on the acronym UDT. I figured if you were on the forum you'd know anyway. Perhaps this is a good time for a glossary for CMSMS if one does not already exist?
Glad my solution worked for you. I'm hoping that the experiences devs are reading this (calguy?) and can make the quick fix necessary to expose the long name (and perhaps alo the parent category) in the $entry object in a future release.
-S