Last active
March 30, 2023 11:48
-
-
Save Lycolia/54b236cf6ed47b24f7bc9f8f16ebb72a to your computer and use it in GitHub Desktop.
YARPP thumbnail template for SANGO theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_post_data($post_id) { | |
$url = esc_url(get_permalink($post_id)); | |
$title = esc_attr(get_the_title($post_id)); | |
$img = ''; | |
if (has_post_thumbnail($post_id)) { | |
$img = get_the_post_thumbnail_url($post_id, 'thumb-520'); | |
} else { | |
$buff = esc_url(get_option('thumb_upload')); | |
$img = replace_thumbnail_src($buff, 'thumb-520'); | |
} | |
return [$url, $title, $img]; | |
} | |
$render_html = <<<EOD | |
<div class="related-posts type_a slide"> | |
<h2>関連記事</h2> | |
EOD; | |
if (!have_posts()) { | |
$render_html .= " <p>関連記事はありません。</p>\n"; | |
} else { | |
$render_html .= " <ul>\n"; | |
while (have_posts()) { | |
the_post(); | |
list($url, $title, $img) = get_post_data($post->id); | |
$render_html .= <<<EOD | |
<li> | |
<a href="$url" rel="bookmark norewrite" title="$title"> | |
<figure class="rlmg"> | |
<img src="$img" alt="$title" width="520" height="300" /> | |
</figure> | |
<div class="rep"><p>$title</p></div> | |
</a> | |
</li> | |
EOD; | |
} | |
$render_html .= " </ul>\n"; | |
} | |
$render_html .= "</div>\n"; | |
echo $render_html; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment