Skip to content

Commit

Permalink
Fallback in case we're missing a featured image
Browse files Browse the repository at this point in the history
  • Loading branch information
Ipstenu committed Feb 21, 2024
1 parent bd1b67f commit 53a5b9b
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 49 deletions.
Binary file added images/mystery-person.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/mystery-show.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 23 additions & 10 deletions template-parts/content-post_type_actors.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,32 @@

// Microformats Fix.
lwtv_microformats_fix( $post->ID );

// Thumbnail attribution.
$thumb_attribution = get_post_meta( get_post_thumbnail_id(), 'lwtv_attribution', true );
$thumb_title = ( empty( $thumb_attribution ) ) ? get_the_title() : get_the_title() . ' © ' . $thumb_attribution;
$thumb_array = array(
'class' => 'single-char-img',
'alt' => get_the_title(),
'title' => $thumb_title,
);
?>

<section class="showschar-section" name="biography" id="biography">
<div class="card-body"><?php the_post_thumbnail( 'character-img', $thumb_array ); ?>
<div class="card-body">
<?php
if ( ! has_post_thumbnail() ) {
// If there is no post thumbnail, use the mystery person image.
?>
<img src="<?php echo esc_url( get_template_directory_uri() ); ?>/images/mystery-person.jpg" class="single-char-img post-image" alt="We have no photo of <?php echo esc_attr( get_the_title() ); ?> at this time." title="Placeholder photo for <?php echo esc_attr( get_the_title() ); ?>" />
<?php
} else {
// Otherwise we have a post thumbnail.

// Thumbnail attribution.
$thumb_attribution = get_post_meta( get_post_thumbnail_id(), 'lwtv_attribution', true );
$thumb_title = ( empty( $thumb_attribution ) ) ? get_the_title() : get_the_title() . ' &copy; ' . $thumb_attribution;
$thumb_array = array(
'class' => 'single-char-img rounded float-left',
'alt' => get_the_title(),
'title' => $thumb_title,
);

// Output Thumbnail.
the_post_thumbnail( 'character-img', $thumb_array );
}
?>
<div class="card-meta">
<div class="card-meta-item">
<?php
Expand Down
63 changes: 37 additions & 26 deletions template-parts/content-post_type_characters.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,40 +113,51 @@
// Microformats Fix
lwtv_microformats_fix( $post->ID );

// Thumbnail attribution
$thumb_attribution = get_post_meta( get_post_thumbnail_id(), 'lwtv_attribution', true );
$thumb_title = ( empty( $thumb_attribution ) ) ? get_the_title() : get_the_title() . ' &copy; ' . $thumb_attribution;
$thumb_array = array(
'class' => 'single-char-img rounded float-left',
'alt' => get_the_title(),
'title' => $thumb_title,
);

// Alt Images
$alt_images = get_post_meta( get_the_ID(), 'lezchars_character_image_group' );
if ( $alt_images ) {
$image_tabs = array();
foreach ( $alt_images[0] as $an_image ) {
$attr_array = array(
'class' => 'single-char-img rounded float-left',
'alt' => get_the_title() . ' ' . $an_image['alt_image_text'],
'title' => $thumb_title . ' - ' . $an_image['alt_image_text'],
);
$image_tabs[] = array(
'title' => $an_image['alt_image_text'],
'slug' => sanitize_title( $an_image['alt_image_text'] ),
'image' => wp_get_attachment_image( $an_image['alt_image_file_id'], 'character-img', false, $attr_array ),
);
// If we have a post thumbnail, get the image and alt images.
if ( has_post_thumbnail() ) {
// Thumbnail attribution
$thumb_attribution = get_post_meta( get_post_thumbnail_id(), 'lwtv_attribution', true );
$thumb_title = ( empty( $thumb_attribution ) ) ? get_the_title() : get_the_title() . ' &copy; ' . $thumb_attribution;
$thumb_array = array(
'class' => 'single-char-img rounded float-left',
'alt' => get_the_title(),
'title' => $thumb_title,
);

// Check post meta for alt images.
$alt_images = get_post_meta( get_the_ID(), 'lezchars_character_image_group' );

// If we have alt images, get them.
if ( $alt_images ) {
$image_tabs = array();
foreach ( $alt_images[0] as $an_image ) {
$attr_array = array(
'class' => 'single-char-img rounded float-left',
'alt' => get_the_title() . ' ' . $an_image['alt_image_text'],
'title' => $thumb_title . ' - ' . $an_image['alt_image_text'],
);
$image_tabs[] = array(
'title' => $an_image['alt_image_text'],
'slug' => sanitize_title( $an_image['alt_image_text'] ),
'image' => wp_get_attachment_image( $an_image['alt_image_file_id'], 'character-img', false, $attr_array ),
);
}
}
}

?>
<div class="card-body">
<div class="character-image-wrapper">
<?php
if ( ! isset( $image_tabs ) || ! is_array( $image_tabs ) ) {
if ( ! has_post_thumbnail() ) {
// If there is no post thumbnail, use the mystery person image.
?>
<img src="<?php echo esc_url( get_template_directory_uri() ); ?>/images/mystery-person.png" class="single-char-img rounded float-left post-image" alt="We have no photo of <?php echo esc_attr( get_the_title() ); ?> at this time." title="<?php echo esc_attr( get_the_title() ); ?>" />
<?php
} elseif ( ! isset( $image_tabs ) || ! is_array( $image_tabs ) ) {
// If there is a post thumbnail and no image tabs, use the post thumbnail.
the_post_thumbnail( 'character-img', $thumb_array );
} else {
// Otherwise we have multiple images, so use the tabs.
?>
<div class="featured-image-tabs ">
<!-- Nav tabs -->
Expand Down
35 changes: 22 additions & 13 deletions template-parts/content-post_type_shows.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,28 @@
// Microformats Fix.
lwtv_microformats_fix( $post->ID );

// Thumbnail attribution.
$thumb_attribution = get_post_meta( get_post_thumbnail_id(), 'lwtv_attribution', true );
$thumb_title = ( empty( $thumb_attribution ) ) ? get_the_title() : get_the_title() . ' &copy; ' . $thumb_attribution;

// Echo the header image.
the_post_thumbnail(
'large',
array(
'class' => 'card-img-top',
'alt' => get_the_title(),
'title' => $thumb_title,
)
);
if ( ! has_post_thumbnail() ) {
// If there is no post thumbnail, use the mystery person image.
?>
<img src="<?php echo esc_url( get_template_directory_uri() ); ?>/images/mystery-show.png" class="card-img-top wp-post-image" alt="We have no photo of <?php echo esc_attr( get_the_title() ); ?> at this time." title="<?php echo esc_attr( get_the_title() ); ?>" />
<?php
} else {
// We have a thumbnail, so let's use it.

// Thumbnail attribution.
$thumb_attribution = get_post_meta( get_post_thumbnail_id(), 'lwtv_attribution', true );
$thumb_title = ( empty( $thumb_attribution ) ) ? get_the_title() : get_the_title() . ' &copy; ' . $thumb_attribution;

// Echo the header image.
the_post_thumbnail(
'large',
array(
'class' => 'card-img-top',
'alt' => get_the_title(),
'title' => $thumb_title,
)
);
}
?>

<section id="toc" class="toc-container card-body">
Expand Down

0 comments on commit 53a5b9b

Please sign in to comment.