Keyword

[SOLVED] Author in Tag Listings

  • Tom
  • Tom's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 11 months ago #112866 by Tom
[SOLVED] Author in Tag Listings was created by Tom
Hi there,

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
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
11 years 11 months ago #112867 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic Re: Author in Tag Listings
Can you explain an example for what you want to do?

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
  • Tom's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 11 months ago #112868 by Tom
Replied by Tom on topic Re: Author in Tag Listings
Hi Mohamed,

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
11 years 11 months ago #112869 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Author in Tag Listings
Have you tried
					
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • Tom
  • Tom's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 11 months ago #112870 by Tom
Replied by Tom on topic Re: Author in Tag Listings
Hi Krikor,

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
11 years 11 months ago #112871 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Author in Tag Listings
Sorry about my late reply

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
  • Tom's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 11 months ago #112872 by Tom
Replied by Tom on topic Re: Author in Tag Listings
Hi Krikor,

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
11 years 11 months ago #112873 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Author in Tag Listings
You can use the var_dump() command to see all the elements of the object.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • Tom
  • Tom's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 11 months ago #112874 by Tom
Replied by Tom on topic Re: Author in Tag Listings
Hi Krikor,

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
  • Tom's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 11 months ago #112875 by Tom
Replied by Tom on topic Re: Author in Tag Listings
To partly answer my own secondary question - the code Krikor has provided works on the filter.php in the same way as tag listings.

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
11 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
					
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • Tom
  • Tom's Avatar Topic Author
  • Offline
  • Senior Member
More
11 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:
<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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
11 years 11 months ago #112878 by Krikor Boghossian
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.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

  • Tom
  • Tom's Avatar Topic Author
  • Offline
  • Senior Member
More
11 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:
Log in  or Create an account to join the conversation.

More
11 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

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

More
11 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:
<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>
renders to ..."index.php?option=com_k2&view=itemlist&task=user&id=:superuser:"

greetings
cyana

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

More
10 years 9 months ago - 10 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).
<?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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 9 months ago #112883 by Krikor Boghossian
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.

More
10 years 4 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!

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 4 months ago #134506 by Krikor Boghossian
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.