Last active
September 2, 2018 17:24
-
-
Save veritstudio/6bf617822ab376ca65705d3c8144aa7f to your computer and use it in GitHub Desktop.
Simple related posts - Wordpress
This file contains hidden or 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 | |
| $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; ?> |
This file contains hidden or 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
| .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