Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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