Relation field in category workaround?

More
11 years 7 months ago #36070 by victorio404
I'm having items with multiple related items to them.
In category view I can display relation field with titles of all related items, but that creates a long list in some cases.

Is there a way to display only 1 custom text or picture for each main item in category view, even if there are multiple related items?

The idea is just to show if there are some related items or not in category view, but not to show the titles of all of them. With the item HTML setting of the Relation field I can set some custom picture to be shown, but if there are more than one related items the picture repeats corresponding number of times, but I want to have only 1 picture.

I hope this makes sense :)

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

More
11 years 7 months ago #36088 by ggppdk
Hello,
what about display a total count of items (related) via relation field

To do this

1. In Relation field configuration use something basic to make it fast e.g. in custom HTML parameter leave it blank (save it and it will turn into some defaults)

2. use a duplicated template and add your relation field into any template position renderonly

3. edit category_items.php and place at appropriate place:
Code:
<?php echo JText::_("RELATED_ITEMS_COUNT").": ". (count($item->fields['myrelationfieldname']->value)>0 ? 'it has related items' : 'no related items') ; ?>

NOTE: above add text "RELATED_ITEMS_COUNT" to your Joomla language strings e.g. in Joomla language manager add it to language overrides, or if you do not want translations replace it above with e.g. "Content Related Total"

NOTE: above $item maybe $items[$i] depends on your template

NOTE: above 'myrelationfieldname' is the name not the label of your relation field

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
11 years 7 months ago #36116 by victorio404
Thank you for the help. For some reason it always displays 0. However that is not exactly what i'm looking to achieve. With this method i will always have something there even if it is 0. I need the field to display a picture or default text only if there is related item.

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

More
11 years 7 months ago #36131 by ggppdk
Hello,
the above code had an error it used ->values correct is ->value

also what you asked is simple, see the above code (i updated)
place what ever you need in there


-- 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
11 years 7 months ago #36204 by victorio404
Now the code works with "$items[$i]", but only if I want to show the count like that:
Code:
<?php echo JText::_("RELATED_ITEMS_COUNT").": ". count($items[$i]->fields['myrelationfieldname']->value); ?>
But with this:
Code:
<?php echo JText::_("RELATED_ITEMS_COUNT").": ". count($items[$i]->fields['myrelationfieldname']->value)>0 ? 'it has related items' : 'no related items' ; ?>
it always shows "no related items" as a result.
I had to remove JText to make it work:
Code:
<?php echo count($items[$i]->fields['field66']->value)>0 ? 'it has related items' : 'no related items' ; ?>
now it is showing if there are related items or not.

Big Thanks for the great support as always! :)

But i have another problem now. If the related item is at finish publishing date state(expired) the indication is still there because the item state in the relation field is [P] maybe? Is there a way to hide the indication if the item is expired?

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

More
11 years 7 months ago #36224 by ggppdk
Well
you could check if items have expired in the template but i am thinking , it is best to add a built-in variable to the relation field ! it makes more sense because the relation field already examines this


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