Skip to content

Instantly share code, notes, and snippets.

@veritstudio
Last active September 2, 2018 17:24
Show Gist options
  • Select an option

  • Save veritstudio/6bf617822ab376ca65705d3c8144aa7f to your computer and use it in GitHub Desktop.

Select an option

Save veritstudio/6bf617822ab376ca65705d3c8144aa7f to your computer and use it in GitHub Desktop.
Simple related posts - Wordpress
<?php
$relatedMeta = get_post_meta(get_the_ID(), 'related_posts', false);
$related = explode(" ", $relatedMeta[0]);
?>
<?php if ($relatedMeta): ?>
<div class="related-posts">
<?php foreach($related as $item): ?>
<div class="related-post">
<a href="<?php echo get_permalink($item) ?>">
<img src="<?php echo get_the_post_thumbnail_url($item) ?>" alt="Thumbnail" class="related-image">
<span class="title"><?php echo get_the_title($item) ?></span>
</a>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
.related-posts {
display: flex;
justify-content: space-between;
margin-top: 55px;
}
.related-post {
flex-basis: 48%;
}
.related-image {
margin-bottom: 10px;
border: 1px solid #7a7a7a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment