Keyword

item author in generic.php

  • Pierre de Mûelenaere
  • Pierre de Mûelenaere's Avatar
  • Offline
  • New Member
More
13 years 2 months ago #77329 by Pierre de Mûelenaere
Replied by Pierre de Mûelenaere on topic item author in generic.php
Hello, 

 

could you give more explainations about how using this code. 

I do not know in which file and where i should add this.

 

Thanks in advance, I'm quite lost in all this but really needing the hack...

 

Pierre
cellardoor_ncx said:

I approve it's working on K2 2.4.1. Thanks Mark ! You saved me couple of hours trying to write it myself.

 

I just wonder if it works with SEF links.

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

More
13 years 2 months ago #77330 by cellardoor_ncx
Replied by cellardoor_ncx on topic item author in generic.php
You have to know if you are making changes to sub-template overrride or to default generic.php file. When you go to /components/com_k2/templates/ you have generic.php there. This one is a default generic view, which means when you change something here, you will change the look of all the categories assigned to -default- sub template (you can select this option in category options in the backend).

 

However, if you work on an override /templates/NAME_OF_YOUR_THEME/html/com_k2/templates/generic.php this means you are actually overriding (replacing) the default generic.php file. When you make changes here, it will apply to all categories with "NAME_OF_YOUR_TEMPLATE" assigned as a sub-template. I hope you get the idea.

If you do, using firebug etc. locate the place in your category view where you want item author to appear, then edit generic.php file and paste the above code there.

 

For example I wanted it to be in <div class="sub-title"> so my code looks like this :

<div class="sub-title">                              <!-- Item author -->                              <?php                                     $config=new JConfig();                                     $query = " SELECT a.id as thisid, a.created_by as createdby, b.id as thisauthorid, b.name as thisauthor "                                     ." FROM #__k2_items AS a "                                     ." LEFT JOIN #__users AS b ON a.created_by=b.id "                                      ." WHERE a.id=$item->id ";                                     $db =& JFactory::getDBO();                                     $db->setQuery( $query );                                     $row = $db->loadObject();                                     $thisauthor = $row->thisauthor;                                     $thisauthorid = $row->thisauthorid;                              ?>                              <span class="catItemAuthor">                                <?php echo JText::_('By');?> <a href="<?php echo $config->live_site?>/index.php?option=com_k2&view=itemlist&task=user&id=<?php echo $thisauthorid;?>&Itemid=<?php echo $_REQUEST["Itemid"];?>"><?php echo $thisauthor; ?></a>                              </span>

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

More
13 years 2 months ago #77331 by Carlos C
Replied by Carlos C on topic item author in generic.php
Question. Will this work for latest items as well? I have my homepage setup with all latest items for multiple categories and I added the code above but got nothing but a blank. Tried the other code form earlier in the thread and same outcome. Any help will be greatly appreciated.

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

More
13 years 2 months ago #77332 by cellardoor_ncx
Replied by cellardoor_ncx on topic item author in generic.php
No, it won't. Latest items, generic (tags) and users all use different methods.

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

  • Visual Impact Web Design
  • Visual Impact Web Design's Avatar
  • Offline
  • New Member
More
13 years 1 month ago #77333 by Visual Impact Web Design
Replied by Visual Impact Web Design on topic item author in generic.php
Thankyou so much! This worked perfectly!!!

cellardoor_ncx said:
You have to know if you are making changes to sub-template overrride or to default generic.php file. When you go to /components/com_k2/templates/ you have generic.php there. This one is a default generic view, which means when you change something here, you will change the look of all the categories assigned to -default- sub template (you can select this option in category options in the backend).

 

However, if you work on an override /templates/NAME_OF_YOUR_THEME/html/com_k2/templates/generic.php this means you are actually overriding (replacing) the default generic.php file. When you make changes here, it will apply to all categories with "NAME_OF_YOUR_TEMPLATE" assigned as a sub-template. I hope you get the idea.

If you do, using firebug etc. locate the place in your category view where you want item author to appear, then edit generic.php file and paste the above code there.

 

For example I wanted it to be in <div class="sub-title"> so my code looks like this :

<div class="sub-title">                              <!-- Item author -->                              <?php                                     $config=new JConfig();                                     $query = " SELECT a.id as thisid, a.created_by as createdby, b.id as thisauthorid, b.name as thisauthor "                                     ." FROM #__k2_items AS a "                                     ." LEFT JOIN #__users AS b ON a.created_by=b.id "                                      ." WHERE a.id=$item->id ";                                     $db =& JFactory::getDBO();                                     $db->setQuery( $query );                                     $row = $db->loadObject();                                     $thisauthor = $row->thisauthor;                                     $thisauthorid = $row->thisauthorid;                              ?>                              <span class="catItemAuthor">                                <?php echo JText::_('By');?> <a href="<?php echo $config->live_site?>/index.php?option=com_k2&view=itemlist&task=user&id=<?php echo $thisauthorid;?>&Itemid=<?php echo $_REQUEST["Itemid"];?>"><?php echo $thisauthor; ?></a>                              </span>

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


Powered by Kunena Forum