File: /hosting/kak.bg/web/wp-content/themes/kak/includes/related-posts.php
<?php
/**
* The template for displaying the related posts.
* Gets the related posts using the same tags.
* If no thre are no tags, displays the latest posts.
*
* @package WordPress
* @file related-posts.php
* @author FairPixels
* @link http://fairpixels.com
*
**/
?>
<?php
$number = 3;
$args = array();
$args2 = array();
$post_author = 0;
$post_author = $post->post_author;
$categories = get_the_category($post->ID);
$all_posts = 0;
if ($categories) {
$category_ids = array();
foreach($categories as $cat) $category_ids[] = $cat->term_id;
$args = array(
'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'author' => $post_author,
'showposts'=> $number,
);
$all_posts = get_posts($args);
if( count($all_posts) < $number ) {
$n = $number - count($all_posts);
if ($n > 0) {
$args2 = array(
'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'author__not_in' => $post_author,
'showposts'=> $n,
);
$other = get_posts($args2);
$all_posts = array_merge( $all_posts, $other );
}
}
}
if(count($all_posts)){ ?>
<div class="related-posts">
<ul class="list">
<?php
$post_count = 0;
foreach($all_posts as $blog_post): $post=$blog_post; setup_postdata($post);
$last = '';
if (++$post_count == 3) {
$last = ' col-last';
}
?>
<li class="<?php echo $last; ?>">
<?php if ( has_post_thumbnail() ) { ?>
<div class="thumbnail">
<a href="<?php the_permalink(); ?>" >
<?php the_post_thumbnail( 'fp370_215' ); ?>
</a>
</div>
<?php } ?>
<h6>
<a href="<?php the_permalink() ?>">
<?php the_title(); ?>
</a>
</h6>
<?php $user_catid = get_user_meta($post->post_author, 'user_category'); ?>
<?php if (count($user_catid)): ?>
<div class="entry-meta">
<a class="tag" href="<?php echo get_category_link($user_catid[0]); ?>"><?php echo get_cat_name($user_catid[0]); ?></a>
</div>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php } ?>