- Posts: 41
COMMUNITY FORUM
[SOLVED] Author in Tag Listings
- Tom
-
Topic Author
- Offline
- Senior Member
Have found several threads requesting the same thing, but none seem to have an answer.
Basically, I would like to be able to add the author (linked) to items listed under a particular tag.
The usual php approaches don't seem to work this time.
Any help greatly appreciated.
Thanks, Tom.
Please Log in or Create an account to join the conversation.
- Mohamed Abdelaziz
-
- Offline
- Platinum Member
- Joomla Developer
Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store
Please Log in or Create an account to join the conversation.
- Tom
-
Topic Author
- Offline
- Senior Member
- Posts: 41
Thanks for coming back to me.
In short. I am working on a news site that has several titles listed (individually) as categories.
Each category has a subsequent "tag" which is the issue number of that particular title.
Therefore, when someone clicks through the "tag" they see all items from that issue.
The problem is that items have different authors which for some reason, are unable to be displayed in the tag listing layout.
I have tried inserting various bits of PHP into the tag layout file, but this doesn't work. There seems to be several topics on this, but not a concrete answer.
Thanks
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Tom
-
Topic Author
- Offline
- Senior Member
- Posts: 41
No joy - unfortunately.
Just seems a bit odd that it isn't an option in the tag listing settings.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
For the author name this should do the trick
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Tom
-
Topic Author
- Offline
- Senior Member
- Posts: 41
Many thanks for this - think this has got me 75% of the way!
Is there anything extra that could be inserted to make the authors linked?
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Tom
-
Topic Author
- Offline
- Senior Member
- Posts: 41
Thank you for your response.
I'm afraid the above exposes my lack of knowledge with regards to PHP...
Not quite sure how to proceed - I just want the author names to be linked, such as with other layouts (category item etc.)
Also having trouble getting the Author into the search results page. I am using the k2 filter and search module, so am editing filter.php as opposed to generic.php - it's the right file, but none of the author approaches have worked thus far.
Again, many thanks in advance for any assistance.
Please Log in or Create an account to join the conversation.
- Tom
-
Topic Author
- Offline
- Senior Member
- Posts: 41
Just need to get the links functioning and I'll be a happy chappy.
Thanks!
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
You should put this code in tag.php ( in your template overrides ).
For the search result the template file used is generic.php indeed but since I have not uses K2 filter before, I think the extension's developers will provide you with a better answer.
As for the links you use the following variables and echo them inside your HTML code
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Tom
-
Topic Author
- Offline
- Senior Member
- Posts: 41
I've got the following code in tag.php:
<div class="tagauthoredit">
<?php echo $user = JUser::getInstance($item->created_by) ?>
<a href="<?php echo $link = K2HelperRoute::getUserRoute($user->id) ?>"><?php echo JUser::getInstance($item->created_by)->name; ?></a>
</div>
The links are working perfectly.... but I'm getting "JUser" before the author name/link.
I'm terrible with PHP - my apologies. Is there anything you can spot above that would need to be changed?
I have tried taking a few bits out, but it breaks the link and gives an error of "JUser: :_load: Unable to load user with ID: xxxx"
Thanks again for your help thus far.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Check any other items that have been created from a user who has the correct credentials and has not been deleted.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Tom
-
Topic Author
- Offline
- Senior Member
- Posts: 41
But on the off chance anyone has similar requirements, I have been able to hide the "JUser" text by wrapping it in <p> tags and hiding with CSS.
Final code to insert (can also confirm this works with filter.php and presumably generic.php) is:
Log in or Create an account to join the conversation.
- Cyana
-
- Offline
- New Member
- Posts: 10
<?php echo $user = JUser::getInstance($item->created_by) ?>
I don't know why you do this, however omitting the complete line cures the problem. Otherwise, it just works perfect, thanks a lot!
hth
cyana
Please Log in or Create an account to join the conversation.
- Cyana
-
- Offline
- New Member
- Posts: 10
I fixed it quite brute, because I'm not even a newbie to php:
the href line should look like that:
<a rel="author" href="index.php?option=com_k2&view=itemlist&task=user&id=<?php echo JUser::getInstance($item->created_by)->id ?>"><?php echo JUser::getInstance($item->created_by)->name; ?></a>
Maybe another one can come up with a more elegant solution. The problem is to get the user link path tied to the correct user id. The original line
a rel="author" href="<?php echo $link = K2HelperRoute::getUserRoute($user->id) ?>"><?php echo JUser::getInstance($item->created_by)->name; ?></a>
greetings
cyana
Please Log in or Create an account to join the conversation.
- Drago
-
- Offline
- New Member
- Posts: 2
I was looking to display the author of an item in the "latest items", and although the thread is about "tag listings" it helped me solve my problem.
I am posting my solution in the hopes that it will help other people.
Step 1.
Create an override to the file you are editing. (In my case latest_items.php)
Step 2
Set the variable $user (per the example of the previous posters).
<?php $user = JUser::getInstance($this->item->created_by); ?>
Note that the "echo" in this line has been stripped. This is what is causing the "JUser" to appear in the case of the above given solutions.
Step 3
Proceed to creating the link
<a href="<?php echo $link = K2HelperRoute::getUserRoute($user->id) ?>"><?php echo JUser::getInstance($this->item->created_by)->name; ?></a>
And it should work.
Please note:
I had to add "$this" infront of "item->created_by" for the file latest_items.php
This thread refers to tag listings and I have not tested this solution for that specific case.
Reading through this thread it is my understanding that "$this" should be omitted.
Feel free to add it if stuff does not work out for you.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Shir Ekerling
-
- Offline
- New Member
- Posts: 7
maybe do you know a way to have the author image also inside the tag.php?
Thanks!
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
<?php echo var_dump(JUser::getInstance($this->item->created_by)); ?>
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.