Skip to content

Instantly share code, notes, and snippets.

@rilwis
Forked from kutoi94/Create Related Posts with Meta Box Plugin
Last active August 16, 2019 09:27
Show Gist options
  • Save rilwis/557738da92116ceac2b9eb7ab2cf423b to your computer and use it in GitHub Desktop.
Save rilwis/557738da92116ceac2b9eb7ab2cf423b to your computer and use it in GitHub Desktop.
Create Related Posts with Meta Box Plugin
<?php
$field_id = 'related_posts';
$related_posts = rwmb_meta( $field_id );
if (isset($related_posts)) { ?>
<div id="relatedPosts" class="related-posts">
<h3 class="related-posts-headline"><em>You might also like</em></h3>
<div class="related-posts-items jp-related-posts-grid">
<?php foreach ($related_posts as $related_post) { ?>
<div class="related-post-item">
<a class="related-post-a" href="<?php echo get_the_permalink($related_post); ?>" title="<?php echo get_the_title($related_post); ?>" rel="nofollow">
<img class="related-post-img" src="<?php echo get_the_post_thumbnail_url($related_post, 'thumbnail'); ?>" alt="<?php echo get_the_title($related_post); ?>">
</a>
<h4 class="related-post-title">
<a class="related-post-a" href="<?php echo get_the_permalink($related_post); ?>" title="<?php echo get_the_title($related_post); ?>" rel="nofollow"><?php echo get_the_title($related_post); ?></a>
</h4>
<p class="related-post-excerpt"><?php the_excerpt($related_post); ?></p>
</div>
<?php } ?>
</div>
</div>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment