Keyword

Add author link & author name in Latest Items

More
11 years 4 months ago #113790 by aik
Hi all!

Please, tell me, how can I add autor name & author link in a template file latest_item.php?


Copy this code
                <?php if($this->item->params->get('itemAuthor')): ?>
                <!-- Item Author -->
                <div class="catItemAuthorBlock" title="Автор поста">
                        <span class="catItemAuthorNew">
                                <?php if(empty($this->item->created_by_alias)): ?>
                                <a rel="author" href="<?php echo $this->item->author->link; ?>"><?php echo $this->item->author->name; ?></a>
                                <?php else: ?>
                                <?php echo $this->item->author->name; ?>
                                <?php endif; ?>
                        </span>
                </div>    
                <?php endif; ?>

from item.php not work


Please HELP!

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

  • Yiota
  • Yiota's Avatar
  • Visitor
11 years 4 months ago #113791 by Yiota
You could try without the if statement. The if statement checks if the parameter is true through the category params. However, in this view the author is not available by default. Therefore, this if statement never runs. So, try the definition like this:
<!-- Item Author -->
  <div class="catItemAuthorBlock">
    <span class="catItemAuthorNew">
      <?php if(empty($this->item->created_by_alias)): ?>
      <a rel="author" href="<?php echo $this->item->author->link; ?>"><?php echo $this->item->author->name; ?></a>
      <?php else: ?>
      <?php echo $this->item->author->name; ?>
      <?php endif; ?>
    </span>
  </div> 

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

More
11 years 4 months ago #113792 by aik
Not work, I try this.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
11 years 4 months ago #113793 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Add author link & author name in Latest Items
First of all triple posting will NOT get your question answered sooner.

Now, if you are using the latest items by user menu type the variable you are looking for is located in latest.php.

A sample code is:
getk2.org/community/New-to-K2-Ask-here-first/176077-Author-in-Tag-Listings#176558

PS. you might want to rename the $user variable in the latter snippet to avoid any conflicts.

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

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

More
11 years 4 months ago - 11 years 4 months ago #113794 by aik
Hi, Krikor

Thanks for your reply.

I try take the code from this thread (getk2.org/community/New-to-K2-Ask-here-first/176077-Author-in-Tag-Listings#176558)

But I have some problems:

When I paste only this code:
<?php echo  $link = K2HelperRoute::getUserRoute($user->id) ?>

I see a link, but without ID on the end:

My example here: index.php?option=com_k2&view=itemlist&task=user&id=:2013-05-31-16-08-08

You see? No user id after "...task-user&id=:..."


Next problem:

When I add this code:
<?php echo JUser::getInstance($item->created_by)->name; ?>

I don't take any user name, i take only error text:

JUser :: _load: User does not exist


Please do not leave me with this problem!

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

More
11 years 4 months ago #113795 by aik
Hi, all

I find solution for this problem!
Here: www.seoratings.ru/blog/joomla/dobavit-imya-avtora-k-poslednim-materialam-k2-v-joomla-2-5

— find file item.php here: components\com_k2\models
— open in Notepad ++
— find string: 228

Add this parametr: || ($view == 'latest')

And then in template add script

<?php echo $this->item->author->name; ?>

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

More
11 years 4 months ago #113796 by Leon Licht
Replied by Leon Licht on topic Re: Add author link & author name in Latest Items
Thank you so much! You solved my problem!!!

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


Powered by Kunena Forum