Add "default image" instead of empty image

Post Reply
Gohh
Ssr. Bludit
Posts: 11
Joined: Fri Aug 23, 2019 11:32 pm

Wed Apr 08, 2020 12:58 pm

Hello, if the image of the post is not selected, how to add "default image"? I print this:

Code: Select all

<?php if ($page->coverImage()) : ?>
    <a href="<?php echo $page->permalink(); ?>">
        <img src="<?php echo $page->coverImage(); ?>">
    </a>
<?php endif ?>
User avatar
Edi
Site Admin
Posts: 1836
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Contact:

Wed Apr 08, 2020 1:38 pm

Then you have to add an else condition with the path to the default image.
Planet Bludit, Tipps, Snippets und nützliche Links. - Newsletter, Informationen zu Bludit (auf Deutsch).
Gohh
Ssr. Bludit
Posts: 11
Joined: Fri Aug 23, 2019 11:32 pm

Wed Apr 08, 2020 2:25 pm

Edi wrote:
Wed Apr 08, 2020 1:38 pm
Then you have to add an else condition with the path to the default image.
Thank you, it worked!

Code: Select all

<?php if (empty($page->coverImage())) : ?>
	<img src="<?php echo '/bl-themes/1/img/default-img.jpg' ?>" alt="">
<?php endif ?>
How can I get a link to the current theme?
Post Reply