Advertisement
fayway

yarpp-template-thumbs_5.php

Jun 4th, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.81 KB | None | 0 0
  1. <?php
  2. /*
  3. To limit this template to a max related posts number, rename this file to something_X.php where X is your digit limit
  4. example : yarpp-template-thumbs_5.php
  5. */
  6. ?>
  7.  
  8. <?php
  9.  $limit = 0;
  10.  if (preg_match("/.+_(\d+)\.php/i", __FILE__, $matches)) {
  11.    $limit =  $matches[1];
  12.  }
  13.  if ($related_query->have_posts()):?>
  14.     <h4 class="meta">You may be interested in:</h4>
  15.  
  16.     <ol class="related-posts">
  17.       <?php if($limit) $i=0; ?>
  18.         <?php while ($related_query->have_posts()) : $related_query->the_post(); ?>
  19.       <?php if($limit) {
  20.               $i++;
  21.               if($i>$limit) break;
  22.             }
  23.       ?>
  24.             <li>
  25.                 <?php
  26.                     $img = '';
  27.                     if ( has_post_thumbnail() ) {
  28.                         $img = get_the_post_thumbnail( $post->ID, 'related-thumbnail', array( 'title' => $title, 'alt' => $title ) );
  29.                     }
  30.                     else {
  31.                         $attachments = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image',  'numberposts' => 1 ) );
  32.  
  33.                         if ( count( $attachments ) > 0 ) {
  34.                             $img = array_shift( $attachments );
  35.                             $img = wp_get_attachment_image( $img->ID, 'related-thumbnail', true );
  36.                         }
  37.                     }
  38.  
  39.                     $extra_class = '';
  40.                     if ( $img == '' ) {
  41.                         $img         = wp_html_excerpt( get_the_excerpt(), 40 );
  42.                         $extra_class = ' related-thumb-text';
  43.                     }
  44.                 ?>
  45.                 <div class="related-post">
  46.                     <div class="related-thumb<?php echo $extra_class; ?>">
  47.                         <a href="<?php the_permalink() ?>" rel="bookmark">
  48.                             <?php echo $img; ?>
  49.                         </a>
  50.                     </div>
  51.                    
  52.                     <div class="related-title">
  53.                         <a href="<?php the_permalink() ?>" rel="bookmark">
  54.                             <?php the_title(); ?>
  55.                         </a>
  56.                     </div>
  57.                 </div>
  58.             </li>
  59.  
  60.         <?php endwhile; ?>
  61.     </ol>
  62.     <div style="clear: both"></div>
  63.    
  64. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement