<?php
/*
To limit this template to a max related posts number, rename this file to something_X.php where X is your digit limit
example : yarpp-template-thumbs_5.php
*/
?>
<?php
$limit = 0;
if (preg_match("/.+_(\d+)\.php/i", __FILE__, $matches)) {
$limit = $matches[1];
}
if ($related_query->have_posts()):?>
<h4 class="meta">You may be interested in:</h4>
<ol class="related-posts">
<?php if($limit) $i=0; ?>
<?php while ($related_query->have_posts()) : $related_query->the_post(); ?>
<?php if($limit) {
$i++;
if($i>$limit) break;
}
?>
<li>
<?php
$img = '';
if ( has_post_thumbnail() ) {
$img = get_the_post_thumbnail( $post->ID, 'related-thumbnail', array( 'title' => $title, 'alt' => $title ) );
}
else {
$attachments = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => 1 ) );
if ( count( $attachments ) > 0 ) {
$img = array_shift( $attachments );
$img = wp_get_attachment_image( $img->ID, 'related-thumbnail', true );
}
}
$extra_class = '';
if ( $img == '' ) {
$img = wp_html_excerpt( get_the_excerpt(), 40 );
$extra_class = ' related-thumb-text';
}
?>
<div class="related-post">
<div class="related-thumb<?php echo $extra_class; ?>">
<a href="<?php the_permalink() ?>" rel="bookmark">
<?php echo $img; ?>
</a>
</div>
<div class="related-title">
<a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
</a>
</div>
</div>
</li>
<?php endwhile; ?>
</ol>
<div style="clear: both"></div>
<?php endif; ?>