Display List of Post other than which is open from one category


<div>
<?php
if ( is_single() )
{
$cats = wp_get_post_categories($post->ID);
if ($cats)
{
$first_cat = $cats[0];
$args=array(
'cat' => $first_cat, //cat__not_in wouldn't work
'post__not_in' => array($post->ID),
'showposts'=>5,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() )
{
echo '<h3 class="widget-title" style="height:40px;">Related Posts</h3>';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div style="height:85px; font-size:14px; color:#555555; font-weight:bold; line-height:22px;">
<?php if(catch_that_image() == '/images/default.jpg'): ?>
<img src="<?php echo esc_url( home_url( '/' ) ); ?>/wp-content/uploads/2013/05/default.jpg" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" align="left" hspace="5" width="105" />
<div style="padding-left:115px;">
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>" style=" text-decoration:none; color:#333;">
<?php the_title(); ?>
</a>
</div>
<?php else : ?>
<img src="<?php echo catch_that_image();?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" align="left" hspace="5" width="105" />
<div style="padding-left:115px;">
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>" style=" text-decoration:none; color:#333;">
<?php the_title(); ?>
</a>
</div>
<?php endif; ?>
</div>
<?php endwhile;
}
}
wp_reset_query(); // Restore global post data stomped by the_post().
}
?>
</div>

In this code above I have used catch_that_image() function. This function is used to display the image which is present in the post to the listing page. For the function click here.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.