Relation field in category workaround?

More
12 years 10 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
12 years 10 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 review. Thanks!

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

More
12 years 10 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
12 years 10 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 review. Thanks!

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

More
12 years 10 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
12 years 10 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 review. Thanks!

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

More
12 years 10 months ago #36428 by victorio404
Is there a chance to have this variable in some of the next releases?
If not, can you please tell me how to check if the item is expired in the template?

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

More
12 years 4 months ago #40899 by binbenik
Hello,

I followed your process:

1. I created a Relation field
2. I used a duplicated template and add my relation field into position renderonly
3. I edited category_items.php in my duplicate template folder 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' ; ?>

Problem, nothing change.
To test, I also try to add only text after title without success.
If I add a field in my duplicate template via the administrator site, it works and I see it on my site but when I change the code, it's like I change the wrong file.

Do you have an idea ?

Frederic

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

More
12 years 4 months ago #40902 by ggppdk
Hello

-- yes, there is a problem with the above code,
the expression always evaluate to true,
due to JText string being always non-empty

... a set of () parenthesis is needed, i have corrected the code above, it must be like this (notice that i added the parenthesis):
Code:
<?php echo JText::_("RELATED_ITEMS_COUNT").": ". (count($item->fields['myrelationfieldname']->value)>0 ? 'it has related items' : 'no related items'); ?>


-- 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 4 months ago #40903 by binbenik
Thanks for your quick reply and for the code.

My problem is when I add code in category_items.php, nothing happens.
I configure my category to use this duplicate template.
When I drag and drop a field under my duplicate template in administrator site, I can see the result on my site.
I also try to add a simple text after title without success.

Seems like category_items.php in the folder of my duplicate template is not used.

Any idea ?

Frederic

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