Thank you for your post. It is working, but how can I put the intro image instead? like insted of looking in the articles image, it looks for the intro image in the article.pangolin wrote:In the five odd years since joomjbo posted the code above, the file names and variables have changed slightly.
The file you need to copy is now /components/com_content/views/category/tmpl/default_articles.php
You need to copy it to /templates/[the template you use]/html/com_content/category/default_articles.php
(Nb you will need to do this for each template you use. Editing the file in place is not recommended as it will get overwritten when you upgrade joomla)
The edits you need to make are as follows:
The line of code you need to find isThe $item variable is now $article, so the code you need to add after the previous line is:Code: Select all
<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catid)); ?>">
Code: Select all
<?php $text = $article->introtext; if(preg_match('/<\s*img[^>]+>/Ui', $text, $matches)){ $image=$matches[0]; $text = str_replace($image,'',$text); } if ($matches) { $image = str_replace('img src="','img width="150px" src="/',$image); $image = str_replace("caption","", $image); echo '' . $image . ''; } else {echo '<img width="150px" src="/images/defaultarticleimage.jpg" class="defaultArticleImage" />';} ?>
Code: Select all
$images = json_decode($this->item->images);
echo $images->image_intro;
Any idea?