- Posts: 15920
COMMUNITY FORUM
[SOLVED] Author in Tag Listings
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
10 years 11 months ago #112876
by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Author in Tag Listings
Hello Tom,
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
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
Less
More
- Posts: 41
10 years 11 months ago #112877
by Tom
Replied by Tom on topic Re: Author in Tag Listings
Thanks Krikor, that's great - I'm 99% of the way now.
I've got the following code in tag.php:
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.
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
Less
More
- Posts: 15920
10 years 11 months ago #112878
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Re: Author in Tag Listings
JUser: :_load: Unable to load user with ID: xxxx" is a message that indicates that your code is correct but the user may have been deleted.
Check any other items that have been created from a user who has the correct credentials and has not been deleted.
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
Less
More
- Posts: 41
10 years 11 months ago #112879
by Tom
Replied by Tom on topic Re: Author in Tag Listings
I have no idea whether this is the most sensible way of fixing the above - very much open to correction...
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:
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
Less
More
- Posts: 10
10 years 4 months ago #112880
by Cyana
Replied by Cyana on topic Re: Author in Tag Listings
I've tweaked around a little bit - the leading "JUser" in your initial code is caused by the second line:
<?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
<?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
Less
More
- Posts: 10
10 years 4 months ago #112881
by Cyana
Replied by Cyana on topic Re: Author in Tag Listings
Ok, there is another problem with the code, the link works only for the superuser, not for other users.
I fixed it quite brute, because I'm not even a newbie to php:
the href line should look like that:
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
renders to ..."index.php?option=com_k2&view=itemlist&task=user&id=:superuser:"
greetings
cyana
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
Less
More
- Posts: 2
9 years 9 months ago - 9 years 9 months ago #112882
by Drago
Replied by Drago on topic Re: Author in Tag Listings
Hello everybody,
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).
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
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.
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
Less
More
- Posts: 15920
9 years 9 months ago #112883
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Re: Author in Tag Listings
Thanks for sharing Drago :)
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
Less
More
- Posts: 7
9 years 5 months ago #134498
by Shir Ekerling
Replied by Shir Ekerling on topic [SOLVED] Author in Tag Listings
Hey guys,
maybe do you know a way to have the author image also inside the tag.php?
Thanks!
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
Less
More
- Posts: 15920
9 years 5 months ago #134506
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic [SOLVED] Author in Tag Listings
You use var_dump to print all the available elements you can use.
<?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.