PHP if (no template part) then…
-
Hi, part of my theme has this php code:
if ( ! is_search() ) { get_template_part( 'template-parts/featured-image' ); } ?>
I would like to write a condition where if feature-image hasn’t been uploaded by the user, then there is a default square image
how would I do this?
Theme is twenty twentySo far I have this in the featured-image.php
if ( has_post_thumbnail() && ! post_password_required() ) { $featured_media_inner_classes = ''; // Make the featured media thinner on archive pages. if ( ! is_singular() ) { $featured_media_inner_classes .= ' medium'; } ?> <figure class="featured-media"> <div class="featured-media-inner section-inner<?php echo $featured_media_inner_classes; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- static output ?>"> <?php the_post_thumbnail(); $caption = get_the_post_thumbnail_caption(); if ( $caption ) { ?> <figcaption class="wp-caption-text"><?php echo wp_kses_post( $caption ); ?></figcaption> <?php } ?> <!-- .featured-media --> <?php if ( !has_post_thumbnail() && ! post_password_required() ) { $featured_media_inner_classes = 'no-img'; // Make the featured media thinner on archive pages. if ( ! is_singular() ) { $featured_media_inner_classes .= ' medium'; } ?> <figure class="no-featured-media"> <div class="no-featured-media-inner section-inner<?php echo $featured_media_inner_classes; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- static output ?>"> <img src="https://st4.depositphotos.com/17828278/24401/v/600/depositphotos_244011872-stock-illustration-image-vector-symbol-missing-available.jpg" alt=""> </div><!-- .featured-media-inner --> </figure> <?php } }
The page I need help with: [log in to see the link]
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘PHP if (no template part) then…’ is closed to new replies.