problem with related posts
-
Hi,
I try to add related posts after post navigation, but i have two problem.
1- related posts field don’t respansive
2- related posts field Not isolated from comments field. I add
to end of code, but it need almost 20
for isolate from comments fiels.my code :
for single post :<div class=”relatedposts”>
<h3>related posts</h3>
<?php $orig_post = $post; global $post;
$tags = wp_get_post_tags($post->ID);
if ($tags) :
$tag_ids = array();
foreach($tags as $individual_tag){
$tag_ids[] = $individual_tag->term_id;
$args=array(
‘tag__in’ => $tag_ids,
‘post__not_in’ => array($post->ID),
‘posts_per_page’=>4, // number related posts.
‘ignore_sticky_posts’ => 1
);
}
$my_query = new wp_query( $args );
while( $my_query->have_posts() ) :
$my_query->the_post(); ?>
<div class=”relatedthumb”>
“><?php the_post_thumbnail(array(150,100)); ?>
<?php the_title(); ?>
</div>
<? endwhile;
endif;
$post = $orig_post;
wp_reset_query(); ?>
</div>CSS:
.relatedposts {
font-size: 12px;
width: 200px;
}
.relatedposts h3 {
font-size: 20px;
margin: 0 0 5px;
}
.relatedthumb {
float: right;
margin: 0 1px;
}
.relatedthumb img {
margin: 0 0 3px;
padding: 0;
}
.relatedthumb a {
color: #333333;
display: block;
padding: 4px;
text-decoration: none;
width: 150px;
}
.relatedthumb a:hover {
background-color: #DDDDDD;
color: #000000;
}
The topic ‘problem with related posts’ is closed to new replies.
