Guest User

A better standard related posts

a guest
Nov 16th, 2015
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.33 KB | None | 0 0
  1. <div class="section section-post-related">
  2.         <div class="section_wrapper clearfix">
  3.  
  4.             <?php
  5.                 $thispostid = get_the_ID();
  6.                 if( mfn_opts_get( 'blog-related' ) ){
  7.                    
  8.                     $tags = wp_get_post_tags($thispostid);
  9.                     if ($tags) {
  10.                         $tag_ids = array();
  11.                         foreach($tags as $individual_tag):
  12.                             $tag_ids[] = $individual_tag->term_id;
  13.                         endforeach;
  14.                         $args=array(
  15.                             'tag__in' => $tag_ids,
  16.                             'post__not_in' => array($post->ID),
  17.                             'posts_per_page'=>3,
  18.                             'caller_get_posts'=>1,
  19.                         );
  20.                     } else if( $aCategories = wp_get_post_categories( $thispostid )) {
  21.    
  22.                         $args = array(
  23.                             'category__in'          => $aCategories,
  24.                             'ignore_sticky_posts'   => true,
  25.                             'no_found_rows'         => true,
  26.                             'post__not_in'          => array( get_the_ID() ),
  27.                             'posts_per_page'        => 3,
  28.                             'post_status'           => 'publish',                      
  29.                         );
  30.                     }
  31.  
  32.  
  33.                     $query_related_posts = new WP_Query( $args );
  34.                     if( $query_related_posts->have_posts() ){
  35.  
  36.                         echo '<div class="section-related-adjustment">';
  37.                             echo '<h4>'. $translate['related'] .'</h4>';
  38.                            
  39.                             while ( $query_related_posts->have_posts() ){
  40.                                 $query_related_posts->the_post();
  41.                                
  42.                                 $classes_rel = '';
  43.                                 if( ! mfn_post_thumbnail( get_the_ID() ) ) $classes_rel .= 'no-img';
  44.                                
  45.                                 echo '<div class="column one-third post-related '. implode( ' ', get_post_class( $classes_rel ) ).'">';
  46.                                    
  47.                                     if( get_post_format() == 'quote'){
  48.  
  49.                                         echo '<blockquote>';
  50.                                             echo '<a href="'. get_permalink() .'">';
  51.                                                 the_title();
  52.                                             echo '</a>';
  53.                                         echo '</blockquote>';
  54.                                        
  55.                                     } else {
  56.  
  57.                                         echo '<div class="image_frame scale-with-grid">';
  58.                                             echo '<div class="image_wrapper">';
  59.                                                 echo mfn_post_thumbnail( get_the_ID() );
  60.                                             echo '</div>';
  61.                                         echo '</div>';
  62.                                        
  63.                                     }
  64.                                    
  65.                                     echo '<div class="date_label">'. get_the_date() .'</div>';
  66.                                
  67.                                     echo '<div class="desc">';
  68.                                         if( get_post_format() != 'quote') echo '<h4><a href="'. get_permalink() .'">'. get_the_title() .'</a></h4>';
  69.                                     echo '</div>';
  70.                                    
  71.                                 echo '</div>';
  72.                             }
  73.                            
  74.                         echo '</div>';
  75.                     }
  76.                     wp_reset_postdata();
  77.                 }  
  78.             ?>
  79.            
  80.         </div>
  81.     </div>
Advertisement
Add Comment
Please, Sign In to add comment