Related post in wordpress


Here is the solution atlast i have landed up for my question.I was trying to pull a post image based on the category.Here is the Solution with the code.

<?php
$category = get_the_category($post->ID);
$current_post = $post->ID;
$posts = get_posts('numberposts=4&category=' . $category[0]->cat_ID . '&exclude=' . $current_post);
?>
<div style="height:100px;background:#EEE;clear:both;">
<div style="font-size:13px;font-weight:bold;">Related Post</div>
<ul style="list-style:none;margin:0;">
<?php
foreach($posts as $post) {
?>
    <li><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php $im_url= get_post_meta($post->ID, 'postimage', true);

 if(empty($im_url)) { $im_url = catch_that_image(); ?>



<img src="<?php echo $im_url; ?>"/>

<?php }else {?>

<img style="padding:2px;height:100px;" align="left" src="<?php echo $im_url; ?>"  />

<?php }?></a></li>
<?php
}
?>
</ul>
</div>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s