[SOLVED] Display only primary category on front-end

More
12 years 9 months ago - 12 years 9 months ago #16920 by momentis
In the Category template view, we have the option to display an item's category. On the front-end, this will output ALL categories the item is assigned to. Is there a way to display ONLY an item's primary category in this list?
Last edit: 12 years 9 months ago by momentis.

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

More
12 years 9 months ago #16950 by ggppdk
Hello open the file:
components/com_flexicontent/templates/youtemplate/category_items.php

Immediately after:
Code:
<!-- BOF fields -->
insert:
Code:
<?php if ( isset($item->positions['table']->{'categories'}) ) { // Split up the categories DISPLAY variable and get only the first list($item->positions['table']->{'categories'}->display) = preg_split("/\s*\|\s*/s", $item->positions['table']->{'categories'}->display); } ?>

You could also add an option to your category.xml to have different behavior per category.

But since this may not be included in future version of flexicontent, i don't know if it is good idea.
Tell me if you need different behavior per category. I mean if you want for items of some categories to show all their categories

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 9 months ago #17013 by momentis
Thank you for the reply! However, this code is not providing the item's primary category. It is returning the highest level category for each item, which is not the item's primary category.

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

More
12 years 9 months ago #17015 by ggppdk
Hello,
instead of the above code and at the same place.
Use this code:
Code:
<?php foreach($item->cats as $cat) { if ($cat->id == $item->catid) { $link = JRoute::_(FlexicontentHelperRoute::getCategoryRoute($cat->slug)); $item->positions['table']->{'categories'}->display = "<a href='$link'>".$cat->title.""; break; } } ?>

Also just before:
Code:
<?php foreach ($columns as $name => $label) : ?>
put this to change column header title of categories:
Code:
<?php $columns['categories'] = JText::_( 'Category' ); ?>
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 9 months ago #17024 by momentis
Oh man, thanks!!!! That is absolutely PERFECT!

Thanks a million!
Rick

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

More
12 years 9 months ago #17065 by ggppdk
You are welcome :D


-- 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.279 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