Related-post:
function rp_posts() {
ob_start();
echo '<section id="" class="widget widget_presscore-blog-posts">
<div class="widget-title">SIMILAR POSTS</div>
<ul class = "recent-posts"> ';
?>
<?php
$orig_post = $post;
global $post;
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach ($categories as $individual_category)
$category_ids[] = $individual_category->term_id;
$args = array(
'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'posts_per_page' => 5, // Number of related posts that will be shown.
'caller_get_posts' => 1
);
$my_query = new wp_query($args);
if ($my_query->have_posts()) {
//echo '<div id="related_posts"><ul>';
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<li>
<article class="post-format-standard">
<div class="wf-td">
<a class="alignleft post-rollover this-ready" href="<?php the_permalink() ?>">
<img class="preload-me" src="<?php the_post_thumbnail_url(array(60, 60)); ?>" width="60" height="60" alt="<?php the_title() ?>">
<i></i>
</a>
</div>
<div class="post-content">
<a href="<?php the_permalink() ?>">
<?php the_title() ?>
</a><br>
<time class="text-secondary" datetime="<?php the_time('F j, Y') ?>"><?php the_time('F j, Y') ?></time>
</div>
</article>
</li>
<?php
}
}
$post = $orig_post;
wp_reset_query();
echo ' </ul>
</section>';
}
}
add_shortcode('rp', 'rp_posts');
Show Comments
