Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="related-posts-after-content">
- <?php
- $related_articles = array();
- $categories = get_the_category();
- if($categories) {
- $category_id = $categories[0]->term_id;
- if(count($categories) > 1 && class_exists('WPSEO_Primary_Term')) {
- $primary_term = new WPSEO_Primary_Term('category', get_the_id());
- $category_id = $primary_term->get_primary_term();
- }
- $related_articles = get_posts(array(
- 'category' => $category_id,
- 'exclude' => $post->ID,
- 'numberposts' => 3,
- 'order' => 'RAND',
- 'orderby' => 'date',
- 'post_status' => 'published',
- 'post_type' => 'post'
- ));
- }
- ?>
- <?php if($related_articles): ?>
- <h3>Like this blog post? You'll love these...</h3>
- <section class="related-articles">
- <?php foreach($related_articles as $post): ?>
- <?php setup_postdata($post); ?>
- <article>
- <?php if ( has_post_thumbnail() ) {
- the_post_thumbnail(array(200,150));
- } else { ?>
- <img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />
- <?php } ?>
- <br>
- <h4><a href="<? the_permalink()?>"><?php the_title(); ?></a></h4>
- </article>
- <?php endforeach; ?>
- <?php wp_reset_postdata(); ?>
- </section>
- <?php endif; ?>
- </div>
- <style>
- .related-posts-after-content {padding-top:20px;}
- .related-posts-after-content article {
- display:inline-grid;
- width: 32%;
- text-align:center;
- }
- .related-posts-after-content article img {
- margin:auto;
- }
- .related-posts-after-content h3{
- font-family: Didot, serif;
- font-size: 30px;
- letter-spacing: 1px;
- }
- </style>
Add Comment
Please, Sign In to add comment