Hi,
i understand you are using the related-ads-carousel.php snippet, if so then the JavaScript library which is handling the carousel does not support well entries without an image.
What you would need to do is modify the related-ads-carousel.php to show a default image if the $image_id is null (lines about 66 to 69).
Thread Starter
Carin
(@sparksfreebies)
can you check the code below before I add it to my site, still not 100% sure, thank you so much for your help!
since the function to check for null is: if(empty($ID)){}
But if there is already code to check if $image_id exists
<?php if($image_id): ?>
should I add
if(empty($image_id)){echo div.advert-img {
background-image: url(https://volusiaclassifieds.com/wp-content/uploads/2021/10/ad-default.jpg)};
so it would be:
`<?php $image_id = adverts_get_main_image_id( $post->ID ) ?>
<div class=”advert-img”>
<?php if($image_id): ?>
<?php $image = get_post( $image_id ) ?>
ID ) ) ?>” class=”advert-item-grow” title=”<?php echo esc_attr($image->post_excerpt) ?>” alt=”<?php echo esc_attr($image->post_content) ?>” />
<?php if(empty($image_id)){echo div.advert-img {
background-image: url(https://volusiaclassifieds.com/wp-content/uploads/2021/10/ad-default.jpg)};/>
<?php endif; ?>
</div>
The code should be
<?php if($image_id): ?>
<?php $image = get_post( $image_id ) ?>
<img src="<?php echo esc_attr( adverts_get_main_image( $post->ID ) ) ?>" class="advert-item-grow" title="<?php echo esc_attr($image->post_excerpt) ?>" alt="<?php echo esc_attr($image->post_content) ?>" />
<?php else: ?>
<img src="https://volusiaclassifieds.com/wp-content/uploads/2021/10/ad-default.jpg" class="advert-item-grow" title="default image" alt="default image" />
<?php endif; ?>