Display image in sub category blog view only if file exists

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Post Reply
ginevra
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Mon Mar 18, 2019 10:40 am

Display image in sub category blog view only if file exists

Post by ginevra » Mon Mar 18, 2019 11:27 am

I try to insert this code in my ovveride of blog_children.php to display images in the blog view sub category:

Code: Select all

<?php echo '<img src="'.json_decode($child->params)->image . '" />'; ?>

It works well, but if the image is not present, the missing image icon appears, while I'd prefer the image to not show up at all.
I tried to insert this one too:

Code: Select all

<?php if ($this->params->get ('show_image') && $item->getParams()->get('image')) :?>
<?php echo '<img src="'.json_decode($child->params)->image . '" />'; ?>	
	<?php endif;?>	
but no images appear in any sub category
I use latest joomla version 3.9.4
Could you please give me some code that specifies to show the image only if it exists or any suggestion?

sazbaztaz
Joomla! Apprentice
Joomla! Apprentice
Posts: 44
Joined: Thu Mar 18, 2010 2:20 pm

Re: Display image in sub category blog view only if file exists

Post by sazbaztaz » Tue Mar 19, 2019 1:54 pm

Not sure how the blogview template looks like but I'd approach the solution with print_r and see what options are there.

<?php echo '<pre>'; ?>
<?php print_r($this->params); ?>
//or / and
<?php print_r($this->item); ?>
<?php echo '</pre>'; ?>

Hope it helps.


Post Reply

Return to “Joomla! 3.x Coding”