Skip to content

Commit

Permalink
feat(components): Use fallback as initial image for member list items
Browse files Browse the repository at this point in the history
Set `src` to a fallback image, which will be replaced by `lozad` with 
the correct image source once scrolled into view.
  • Loading branch information
delucis committed Mar 4, 2019
1 parent c145193 commit 5cb1390
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions components/member_list_item.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php
if (!defined('HGNM_SQUARE_PLACEHOLDER_SRC')) {
define(
'HGNM_SQUARE_PLACEHOLDER_SRC',
get_stylesheet_directory_uri() . '/img/fallback-200x200.gif'
);
}

if (!function_exists('member_list_item')) {
/**
* A link to a member with their name and (optionally) photo
Expand All @@ -17,14 +24,12 @@ function member_list_item($opts)
$alt_text = get_post_meta($img_id, '_wp_attachment_image_alt', true);
$imgsrc = wp_get_attachment_image_src($img_id, 'hgnm-thumb');
if (empty($imgsrc)) {
$imgsrc = array(
get_stylesheet_directory_uri() . '/img/fallback-200x200.gif'
);
$imgsrc = array(HGNM_SQUARE_PLACEHOLDER_SRC);
}
if (!$alt_text) {
$alt_text = $member_name;
}
$html .= '<img data-src="' . $imgsrc[0] . '" alt="' . $alt_text . '" class="lozad">';
$html .= '<img src="' . HGNM_SQUARE_PLACEHOLDER_SRC . '" data-src="' . $imgsrc[0] . '" alt="' . $alt_text . '" class="lozad">';
}
$html .= "<span>$member_name</span></a></li>";
return $html;
Expand Down

0 comments on commit 5cb1390

Please sign in to comment.