4

I want to show my article intro text and item image with link to the full article in the result page for Joomla Tags.

Is there a way to do this, or how can I modify the code to get the expected results?

I tried to add in components\com_tags\views\tag\tmpl\default_items.php <?php echo $this->item->introtext; ?> but it does not work there as in other cases. I do not know php well enough, so would like to know if there are other suggestions.

Thanks

3 Answers 3

7

Try this(tested and worked in Joomla 3.3.0):

Put this code:

<?php
//introtext
echo $item->text;
//image
$images  = json_decode($item->core_images);
echo '<img src="'.$images->image_intro.'">';
//get category name by id
$db = JFactory::getDbo();
$id = $item->core_catid;
$db->setQuery("SELECT cat.title FROM #__categories cat WHERE cat.id='$id'");
$category = $db->loadResult();
echo '<p>'.$category.'</p>';
?>

into this file:

templates/yourtemplate/html/com_tags/tag/default_items.php

that should be copied from:

components\com_tags\views\tag\tmpl\default_items.php

between this two lines

<?php foreach ($items as $i => $item) : ?> //Line 63 <?php endforeach; ?>

You can use any of this variables(<?php echo $item->useonefromthelist; ?>) to modify the tag output:

type_alias
content_item_id 
core_content_id
match_count 
tag_date
core_title
core_alias
core_body
core_state
core_access 
core_metadata
core_created_user_id 
core_created_by_alias 
core_created_time 
core_images 
core_modified_time 
core_language 
core_catid 
core_publish_up 
core_publish_down 
content_type_title 
router 
author 
author_email 
link 
displayDate
event
text
core_params

How i get this list?

<pre>
<?php print_r($item); ?>
</pre>
6
  • Firstly, I am doing the override, no worries about this. Secondly, I do not manage to get the wanted result anyway. Which of this variables can give me back the intro text for the articles? What I want is when clicking on a tag in the tag cloud it opens the result page with articles with their intro text and image as in category blog, not only the title as it is now. Is there a way to get this?
    – gag
    May 14, 2014 at 18:03
  • My code does exactly what you need. Look here: projekte.joomla-agentur.de/law-olesch/index.php/de/component/… This is the Tags page with an image and the intro text. I Update my answer. Try it. May 14, 2014 at 18:26
  • That's great, it works as I need. I even put the code on line 72 (after <h3>) and get link to my article. Thanks a lot. Sorry, I do not have enough reputation to vote for you(.
    – gag
    May 14, 2014 at 19:14
  • And I would like to ask one more question. As far as I understand we cannot retrieve Category Name and link to the category here, or can we?
    – gag
    May 14, 2014 at 19:43
  • check the answer :-) May 14, 2014 at 23:25
0

1stly, directly editing the template override in situ is not recommended.

Google html overrides for more info but in short, for the case above:

  • copy the tmpl folder from components\com_tags\views\tag to templates/yourtemplate/html/com_tags/
  • rename it to tag

You can edit it there where it won't get overwritten after an update.

For what you want to do above I think you'll find this more complicated than you think. What output would you want where a tag is linked to more that one article? What I would do here is have a look at modifying a module that already does most of what you want. Something like the "Similar Tags" module. It would be easier to make a modified version of that and call that into the tag result page.

2
  • 1
    No, I don't want to link a tag to more articles. I want to click on the tag in the tag cloud module and as a result see something similar with standard joomla category blog, with article intro texts and intro images. Now instead I get only the titles of the articles.
    – gag
    May 14, 2014 at 18:06
  • As I said this would need to be modified. @Joomla Agencys' modified code will provide your requirements.
    – BodgeIT
    May 15, 2014 at 5:59
0

This solution worked very well for myself. The intro text was still too long so I shortened it to 300 characters. See below. I added the main code in the first answer above right after the h3 tag and then just modified the intro text portion. I didn't use the category name. I added the link to the main article in the read more link and also for the ...

Here is the total code I used in Joomla 3.6, including the h3 tag...

<h3>
<a href="<?php echo JRoute::_(TagsHelperRoute::getItemRoute($item->content_item_id, $item->core_alias, $item->core_catid, $item->core_language, $item->type_alias, $item->router)); ?>">
<?php echo $this->escape($item->core_title); ?>
</a> 
</h3>

<?php
//image
$images  = json_decode($item->core_images);
echo '<p><img class="intro-image" src="'.$images->image_intro.'"></p>';                  
//introtext
$limit =300;
if (strlen($item->text) > $limit) {
echo (substr($item->text, 0, $limit)) ?> <a href="<?php echo JRoute::_(TagsHelperRoute::getItemRoute($item->content_item_id, $item->core_alias, $item->core_catid, $item->core_language, $item->type_alias, $item->router)); ?>">...</a>
<?php
}
else {
echo $item->text;
}
?>
<p>
<a class="read-more" href="<?php echo JRoute::_(TagsHelperRoute::getItemRoute($item->content_item_id, $item->core_alias, $item->core_catid, $item->core_language, $item->type_alias, $item->router)); ?>">Read more</a>
</p> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.