Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

Commit

Permalink
Fixed post image appearance for posts without a featured image.
Browse files Browse the repository at this point in the history
  • Loading branch information
peiche committed Nov 1, 2021
1 parent 58137c9 commit 16154c9
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions resources/views/partials/archive-image.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
<?php
$post_format = get_post_format() ?: 'standard';
$image_icon = '<div class="media-wrapper--icon flex items-center justify-center">' .
\Garrick\get_svg( [ 'icon' => 'format-' . $post_format, 'class' => 'icon--md color-inherit' ] ) .
'</div>';

$image_label = '';
$days = get_theme_mod( 'archive_new_days_count', false );
if ( $days > 0 && ( time() - ( 86400 * $days ) ) < get_the_date( 'U' ) ) :
$image_label = '<div class="media-wrapper--label">' . __( 'New', 'garrick' ) . '</div>';
endif;

if ( has_post_thumbnail() && '' != get_the_post_thumbnail_url() ) :
$image_icon = '<div class="media-wrapper--icon flex items-center justify-center">' .
\Garrick\get_svg( [ 'icon' => 'format-' . $post_format, 'class' => 'icon--md color-inherit' ] ) .
'</div>';
$image_label = '';

if ( $days > 0 && ( time() - ( 86400 * $days ) ) < get_the_date( 'U' ) ) :
$image_label = '<div class="media-wrapper--label">' . __( 'New', 'garrick' ) . '</div>';
endif;

Hybrid\Carbon\Image::display( 'featured', [
'size' => 'full',
'class' => 'entry__image radius-md',
'before' => '<figure class="margin-y-sm color-contrast-low media-wrapper media-wrapper--4:3 bg-contrast-lower radius-md position-relative">' . $image_icon . $image_label,
'after' => '</figure>',
'link' => true,
'link_class' => 'entry__featured-image__link',
] );
else :
?>
<?php if ( has_post_thumbnail() && '' != get_the_post_thumbnail_url() ) : ?>
<?php Hybrid\Carbon\Image::display( 'featured', [
'size' => 'full',
'class' => 'entry__image radius-md',
'before' => '<figure class="margin-y-sm color-contrast-low media-wrapper media-wrapper--4:3 bg-contrast-lower radius-md position-relative">' . $image_icon . $image_label,
'after' => '</figure>',
'link' => true,
'link_class' => 'entry__featured-image__link',
] ) ?>
<?php else : ?>
<a href="<?php echo esc_url( get_permalink() ) ?>" class="entry__featured-image__link color-contrast-low" aria-hidden="true">
<div class="margin-y-sm color-contrast-low media-wrapper media-wrapper--4:3 bg-contrast-lower radius-md position-relative">
<?php echo $image_label ?>
<?php echo $image_icon ?>
<?php if ( $days > 0 && ( time() - ( 86400 * $days ) ) < get_the_date( 'U' ) ) : ?>
<div class="media-wrapper--label">
<?php echo esc_html( 'New', 'garrick' ) ?>
</div>
<?php endif ?>
<div class="media-wrapper--icon flex items-center justify-center">
<?php echo \Garrick\get_svg( [ 'icon' => 'format-' . $post_format, 'class' => 'icon--md color-inherit' ] ) ?>
</div>
</div>
</a>
<?php endif; ?>

0 comments on commit 16154c9

Please sign in to comment.