Skip to content

Commit 8519d4f

Browse files
author
Ville
authored
PIEN-8524: Display API image (#152)
Display API image instead of default image
1 parent a0a89d3 commit 8519d4f

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

CHANGELOG.MD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- PIEN-8524: Display API image #152
13+
1014
## [1.8.0] - 2023-04-11
1115

1216
- PIEN-8157: PHP 8.1

models/single.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,18 @@ public function related() : ?array {
8989
? wp_get_post_terms( $item->ID, Category::SLUG )
9090
: [];
9191

92+
$item->api_image_url = get_field( 'image_url', $item->ID );
93+
$has_image = $item->image_id !== 0 || ! empty( $item->api_image_url );
94+
95+
if ( ! $has_image ) {
96+
$item->image_id = Images::get_default_image_id();
97+
}
98+
9299
if ( ! empty( $categories ) ) {
93100
$item->category = $categories[0]->name;
94101
$item->category_link = get_category_link( $categories[0]->ID );
95102
}
96103

97-
$item->image_id = $item->image_id === 0
98-
? Images::get_default_image_id()
99-
: $item->image_id;
100-
101104
if ( ! has_excerpt( $item->ID ) ) {
102105
$item->post_excerpt = $this->get_related_excerpt( $item );
103106
}

partials/views/single/single-related.dust

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,21 @@
1414
{#related.posts}
1515
<div class="column is-6 is-3-widescreen">
1616
<div class="related-posts__item mb-4 mb-0-tablet">
17-
{?image_id}
17+
{?api_image_url}
1818
<div class="image is-4by3">
1919
<a href="{permalink|url}" aria-hidden="true" tabindex="-1">
20-
{@image id=image_id size="large" class="objectfit-image" /}
20+
<img src="{api_image_url|url}" class="objectfit-image" loading="lazy" alt=""/>
2121
</a>
2222
</div>
23-
{/image_id}
23+
{:else}
24+
{?image_id}
25+
<div class="image is-4by3">
26+
<a href="{permalink|url}" aria-hidden="true" tabindex="-1">
27+
{@image id=image_id size="large" class="objectfit-image" /}
28+
</a>
29+
</div>
30+
{/image_id}
31+
{/api_image_url}
2432

2533
{?post_title}
2634
<h3 class="h4 mt-5 mb-5">

0 commit comments

Comments
 (0)