For the native Joomla module "Similar Tags", we have only the article title. How to have also the introtext and the intro image?
Here is the native code with my code tests :
defined('_JEXEC') or die;
JLoader::register('TagsHelperRoute', JPATH_BASE . '/components/com_tags/helpers/route.php');
if ($list) : ?>
<ul class="tagssimilar">
<?php foreach ($list as $i => $item) : ?>
<?php if (empty($item->core_title)) continue; ?>
<li>
<?php if (($item->type_alias == 'com_users.category') || ($item->type_alias == 'com_banners.category')) : ?>
<?= htmlspecialchars($item->core_title, ENT_COMPAT, 'UTF-8') ?>
<?php else: $item->route = new JHelperRoute; ?>
<a href="<?= JRoute::_(TagsHelperRoute::getItemRoute($item->content_item_id, $item->core_alias, $item->core_catid, $item->core_language, $item->type_alias, $item->router)) ?>">
<?= htmlspecialchars($item->core_title, ENT_COMPAT, 'UTF-8') ?>
</a>
<?php endif
My first attempt (part 1): Modify Joomla Tags Result Page
//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;
}
My first attempt (part 2) : Modify Joomla Tags Result Page
//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>';
My second attempt: Adding Images to Latest Articles module ?>
// This gets the image data associated with the article and processes it so PHP can use it properly.
$images = json_decode($item->images);
// This checks the Intro Image exists and isn't empty.
if (isset($images->image_intro) && !empty($images->image_intro)) :
// This displays it.
?>
<div class="thumbnail item-image">
<img src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>" itemprop="image"/>
</div>
<?php endif; ?>
My third attempt: https://www.joomlashack.com/blog/joomla/most-read-intro-images/
$images = json_decode($item->images);
?>
<div class="span4">
<?php if( $images->image_intro ) : ?>
<img src="/<?php echo $images->image_intro; ?>" alt="<?php echo htmlspecialchars($item->title); ?>" />
<?php endif; ?>
<a href="/<?php echo $item->link; ?>">
<?php echo $item->title; ?></a>
</div>
...and the end of the first code block...
</li>
<?php endforeach ?>
</ul>
<?php else : ?>
<span><?= JText::_('MOD_TAGS_SIMILAR_NO_MATCHING_TAGS') ?></span>
<?php endif ?>
if
andforeach
loops AND the constant bouncing between<?php
and?>
In the future please make every attempt to clean up your code and practice consistent tabbing to make your question more attractive to answer. Now, with your coding attempts, which once showed some promise / partial success? What errors did they cause. I am not going to be the one to answer this question, but those who are able will have an easier time if you keep clarifying.