Hi everybody,
I'm using Wordpress last version is 3.9.1.
And my theme using Relate Posts Thumbnails without plugin. But it only show when same tag (ex: 2 posts have same 1 tag). Please help me edit the function to show Related Post Thumbnails via Category.
Code in function.php below:
function get_related_posts($post_id, $tags = array()) {
$query = new WP_Query();
if($tags) {
foreach($tags as $tag) {
$tagsA[] = $tag->term_id;
}
}
$args = wp_parse_args($args, array(
'showposts' => 3,
'post__not_in' => array($post_id),
'tag__in' => $tagsA,
'ignore_sticky_posts' => 1,
));
$query = new WP_Query($args);
return $query;
}
Code in single.php below:
<div class="post-box-wrapper">
<div class="post-box">
<h5>Related Posts</h5>
<?php while($related->have_posts()): $related->the_post(); ?>
<?php if($count == 4): $count = 1; endif; if($count == 3): $class = 'last'; else: $class = ''; endif; ?>
<?php if(has_post_thumbnail()): ?>
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID), 'related-posts-image'); ?>
<div class="related-item <?php echo $class; ?>">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" /></a>
</div>
<?php endif; ?>
<?php $count++; endwhile; ?>
</div>
</div>
Pro wordpress code please help me edit.
Thanks so much.
I'm using Wordpress last version is 3.9.1.
And my theme using Relate Posts Thumbnails without plugin. But it only show when same tag (ex: 2 posts have same 1 tag). Please help me edit the function to show Related Post Thumbnails via Category.
Code in function.php below:
function get_related_posts($post_id, $tags = array()) {
$query = new WP_Query();
if($tags) {
foreach($tags as $tag) {
$tagsA[] = $tag->term_id;
}
}
$args = wp_parse_args($args, array(
'showposts' => 3,
'post__not_in' => array($post_id),
'tag__in' => $tagsA,
'ignore_sticky_posts' => 1,
));
$query = new WP_Query($args);
return $query;
}
Code in single.php below:
<div class="post-box-wrapper">
<div class="post-box">
<h5>Related Posts</h5>
<?php while($related->have_posts()): $related->the_post(); ?>
<?php if($count == 4): $count = 1; endif; if($count == 3): $class = 'last'; else: $class = ''; endif; ?>
<?php if(has_post_thumbnail()): ?>
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID), 'related-posts-image'); ?>
<div class="related-item <?php echo $class; ?>">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" /></a>
</div>
<?php endif; ?>
<?php $count++; endwhile; ?>
</div>
</div>
Pro wordpress code please help me edit.
Thanks so much.