[SOLVED] Display only primary category on front-end

More
14 years 6 months ago - 14 years 6 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: 14 years 6 months ago by momentis.

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

More
14 years 6 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 review. Thanks!

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

More
14 years 6 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
14 years 6 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 review. Thanks!

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

More
14 years 6 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
14 years 6 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 review. Thanks!

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

More
12 years 11 months ago #33270 by dariofal
Hi!
I have the same problem that was posted in this thread. I've followed the steps but for some reason it didn't work.

I think that maybe it has something to do with the version of the Flexi Content, considering that this solution was posted two years ago and that I upgraded mine to 1.5.6 RC9b r1576. Thus, I didn't find BOF fields portion in category_items.php file. Instead of putting the code there, I've pasted it in the portion related to the position of the template.

Tks in advance, I hope you can help me.

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

More
12 years 11 months ago #33277 by ggppdk
There could be difference with the template
e.g. for blog template in file category_items.php , you should use (inside the item loop):
$items[$i] instead of $item

also put :
Code:
error_reporting(E_ALL); ini_set('display_errors',1);

also while testing, place in top of the file (category_items.php), to print warnings of any not defined variables


-- 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 review. Thanks!

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

More
12 years 11 months ago #33603 by dariofal
Hi again!
Sorry for bothering. I've tried your previous solution, but for some reason it didn't work.

I've modified the code taking in account your advice and replacing each $item by $items[$i]:
Code:
<?php foreach ($columns as $name => $label) : ?> <?php foreach($items[$i]->cats as $cat) { if ($cat->id == $items[$i]->catid) { $link = JRoute::_(FlexicontentHelperRoute::getCategoryRoute($cat->slug)); $items[$i]->positions['table']->{'categories'}->display = "<a href='$link'>".$cat->title.""; break; } } ?>

Tks again.

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

Moderators: vistamediajoomlacornerggppdk
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
Save