- Posts: 16
COMMUNITY FORUM
- Forum
- K2 Community Forum
- English K2 Community
- How to show username in comments and real author name in articles?
How to show username in comments and real author name in articles?
- DKcrm
-
Topic Author
- Offline
- New Member
Does anybody know how to show the username for comments and the authorname for written articles?
On our site, www.interclub.dk we have K2 powered articles and comments - How do we show the user's usernames instead of their real names in the comments while keeping the real names for authors of the articles??
Well, after not getting a reply on this, I decided to add some comments..
I have found THIS thread, and a post by B Kemler, suggesting changes to the PHP files to show USER names on articles. I've followed the steps, and succesfully managed to change authors on articles to usernames instead of 'real' names.
In hope that the procedure would be the same for the comments, I tried changing the strings for the comments, but found that they already are called 'userName' - Changing to 'username' or 'name' completely deletes the names in itemview, which of course was not of any help at all, so I changed them back.
I've been trying to go through the different php files of k2 in hope to find the place to make the change - but without success. Isn't there anybody at all, who knows how to keep the real author names on the articles, but to only show USER names in the articles?
Please Log in or Create an account to join the conversation.
- trip
-
- Offline
- New Member
- Posts: 15
did you manage to solve this ?
Matthew
Please Log in or Create an account to join the conversation.
- DKcrm
-
Topic Author
- Offline
- New Member
- Posts: 16
Unforunately no - Do you have a solution or are you stuck the same place as me?
Kr,
Christoffer
Matthew said:Hi Christoffer did you manage to solve this ?
Matthew
Please Log in or Create an account to join the conversation.
- Matthew Philogene
-
- Offline
- New Member
- Posts: 15
The issue is the main table where the user details of K2 are stored do not contain the username...
I have tried to use joomla core to bring this through, but no luck... going to ask Fotis, when he gets a chance...
will let you know
Matthew
Christoffer Müller said:Hi Matthew
Unforunately no - Do you have a solution or are you stuck the same place as me?
Kr,
Christoffer
Matthew said:Hi Christoffer did you manage to solve this ?
Matthew
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Platinum Member
- Posts: 8743
$commentUser = &JFactory::getUser($comment->userID); echo $commentUser->username;
It's not the most efficient way but currently it's the only way to do this.
Please Log in or Create an account to join the conversation.
- trip
-
- Offline
- New Member
- Posts: 15
thanks this has worked.... is it not possible to add this as a field in the K2 user profile, and make it an option to show or hide ?
Matthew
Lefteris Kavadas said:Hi. You can achieve that using a little of PHP and the Joomla! API. You can try this inside your template file at the comment loop:
$commentUser = &JFactory::getUser($comment->userID); echo $commentUser->username;
It's not the most efficient way but currently it's the only way to do this.
Please Log in or Create an account to join the conversation.
- DKcrm
-
Topic Author
- Offline
- New Member
- Posts: 16
Am I working in the Joomla template files, or the components/com_k2/views/comments/tmpl/ - or somewhere else? (maybe item.php under /components/com_k2/templates/default/ ?)
Further help much appreciated :o)
Christoffer
Lefteris Kavadas said:Hi. You can achieve that using a little of PHP and the Joomla! API. You can try this inside your template file at the comment loop:
$commentUser = &JFactory::getUser($comment->userID); echo $commentUser->username;
It's not the most efficient way but currently it's the only way to do this.
Please Log in or Create an account to join the conversation.
- Matthew Philogene
-
- Offline
- New Member
- Posts: 15
goto the file
item.php
search for the words "posted by" there is a line of code which echoes the userName
replace with code above
Hope this helps, as we cannot give exact line of code due to huge change in code..
Matthew
Christoffer Müller said:Ohh... As it seems to be working for Matthew, I would like to get some more details on where to add this exactly?
Am I working in the Joomla template files, or the components/com_k2/views/comments/tmpl/ - or somewhere else? (maybe item.php under /components/com_k2/templates/default/ ?)
Further help much appreciated :o)
Christoffer
Lefteris Kavadas said:Hi. You can achieve that using a little of PHP and the Joomla! API. You can try this inside your template file at the comment loop: $commentUser = &JFactory::getUser($comment->userID); echo $commentUser->username;
It's not the most efficient way but currently it's the only way to do this.
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
Please Log in or Create an account to join the conversation.
- DKcrm
-
Topic Author
- Offline
- New Member
- Posts: 16
It seems to be working now, following the solution given above.. It took some time figuring out which bit of code to change as there were 3 statements like 'echo $comment->userName;' following each other..
If others wants the same change, the item.php (in my case) file is located under [J!installation]/templates/[your template folder]/html/com_k2/templates/default/
- the bit of (working) code looks like the attached picture
Please Log in or Create an account to join the conversation.
- DKcrm
-
Topic Author
- Offline
- New Member
- Posts: 16
It seems to be working now, following the solution given above.. It took some time figuring out which bit of code to change as there were 3 statements like 'echo $comment->userName;' following each other..
If others wants the same change, the item.php (in my case) file is located under [J!installation]/templates/[your template folder]/html/com_k2/templates/default/
- the bit of (working) code looks like the attached picture
Please Log in or Create an account to join the conversation.
- Deborah Nix
-
- Offline
- New Member
- Posts: 7
Please Log in or Create an account to join the conversation.
- Ivor Middleton
-
- Offline
- New Member
- Posts: 1
JoomlaWorks said:
This is something that can be added on your Joomla! template really, in the place where you override the MVC template of the module. We'll add it in 2.4 as an option on mod_k2_comments ;)
Please Log in or Create an account to join the conversation.
- Andy Connell
-
- Offline
- Senior Member
- Posts: 54
Though using 2.4.1 and cant see it as a setting in the back as suggested in fotis's post
Also for anyone else interested, I use the comments module, this too needs changing if you want to display the username.
I searched for "written by" and changed the same piece of code below it.
Found in modules/mod_k2_comments/tmpl/comments.php
Please Log in or Create an account to join the conversation.
- John-Eilif Eliassen
-
- Offline
- New Member
- Posts: 12
Please Log in or Create an account to join the conversation.
- Forum
- K2 Community Forum
- English K2 Community
- How to show username in comments and real author name in articles?