Advertisement
cipher87

Related Posts (Ordered List)

Feb 24th, 2020
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.07 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @link https://kriesi.at/support/topic/change-related-posts-title/
  4.  */
  5. if ( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  6.  
  7. /**
  8.  *  These functions shows a number of posts related to the currently displayed post.
  9.  *  Relations are defined by tags: if post tags match, the post will be displayed as related
  10.  */
  11. global $avia_config;
  12.  
  13.  
  14. $rp = avia_get_option('single_post_related_entries');
  15.  
  16.  
  17.  
  18.  
  19. if(!isset($avia_config['related_posts_config']))
  20. {
  21.     $avia_config['related_posts_config'] = array(
  22.    
  23.     'columns' => 8,
  24.     'post_class' =>  "av_one_eighth no_margin ",
  25.     'image_size' => 'square',
  26.     'tooltip'    => true,
  27.     'title_short'=> false
  28.    
  29.     );
  30.    
  31.     if($rp == "av-related-style-full")
  32.     {
  33.         $avia_config['related_posts_config'] = array(
  34.    
  35.         'columns' => 6,
  36.         'post_class' =>  "av_one_half no_margin ",
  37.         'image_size' => 'square',
  38.         'tooltip'    => false, 
  39.         'title_short'=> true   
  40.         );
  41.     }
  42. }
  43.  
  44. if($rp == "disabled") return;
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. extract($avia_config['related_posts_config']);
  53.  
  54.  
  55. $is_portfolio       = false; //avia_is_portfolio_single();
  56. $related_posts      = false;
  57. $this_id            = $post->ID;
  58. $slidecount         = 0;
  59. $postcount          = ($columns * 1);
  60. $format             = "";
  61. $fake_image         = "";
  62. $tags               = wp_get_post_tags($this_id);
  63.  
  64.  
  65. if (!empty($tags) && is_array($tags))
  66. {
  67.      $tag_ids = array();
  68.      foreach ($tags as $tag ) {
  69.          
  70.          if($tag->slug != "portrait" && $tag->slug != "landscape")
  71.          {
  72.             $tag_ids[] = (int)$tag->term_id;
  73.          }
  74.      }
  75.  
  76.      if(!empty($tag_ids))
  77.      {
  78.  
  79.  
  80.         $my_query = get_posts(
  81.                             array(
  82.                                 'tag__in' => $tag_ids,
  83.                                 'post_type' => get_post_type($this_id),
  84.                                 'showposts'=>$postcount, 'ignore_sticky_posts'=>1,
  85.                                 'orderby'=>'rand',
  86.                                 'post__not_in' => array($this_id))
  87.                             );
  88.  
  89.  
  90.         if (!empty($my_query))
  91.         {
  92.             $extra = 'alpha';
  93.             $count = 1;
  94.             $output = "";
  95.  
  96.             //create seperator
  97.  
  98.             $output .= "<div class ='related_posts clearfix {$rp}'>";
  99.  
  100.  
  101.             $output .= "<h5 class='related_title'>".__('Enjoyed this post?', 'avia_framework')."</h5>";
  102.             $output .= "<ol class='related_entries_container '>";
  103.  
  104.             foreach ($my_query as $related_post)
  105.             {
  106.                 $related_posts = true;
  107.                 $slidecount ++;
  108.                 $format = "";
  109.                 if($is_portfolio) $format = "portfolio";
  110.                 if(!$format) $format = get_post_format($related_post->ID);
  111.                 if(!$format) $format = 'standard';
  112.                 if(!empty($title_short)) $related_post->post_title = wp_trim_words($related_post->post_title, 17);
  113.                
  114.                
  115.  
  116.                 $post_thumbnail_id = get_post_thumbnail_id($related_post->ID);
  117.                 $post_thumb = get_the_post_thumbnail($related_post->ID, $image_size, array('title' => esc_attr(get_the_title($post_thumbnail_id))));
  118.                 $image      = $post_thumb ? $post_thumb : "<span class='related_posts_default_image'>{image}</span>";
  119.                 $fake_image = $post_thumb ? $post_thumb : $fake_image;
  120.                 $extra_class= $post_thumb ? "" : "related-format-visible";
  121.                 $parity     = $slidecount % 2 ? 'Odd' : 'Even';
  122.                 $insert_tooltip = $tooltip == true ? "data-avia-related-tooltip=\"". esc_attr($related_post->post_title)."\"" : "";
  123.                
  124.                 $output .= "<li>\n";
  125.                 $output .= "    <a href='".get_permalink($related_post->ID)."' class='relThumWrap noLightbox' title='".esc_attr($related_post->post_title)."'>\n";
  126.                 $output .=      "<strong class='av-custom-related-title'>".$related_post->post_title."</strong>";
  127.                 $output .=      apply_filters('avf_related_post_loop', "", $related_post);
  128.                 $output .= "    </a>";
  129.                 $output .= "</li>";
  130.  
  131.                 $count++;
  132.                 $extra = "";
  133.  
  134.                 if($count == count($my_query)) $extra = 'omega';
  135.  
  136.             }
  137.  
  138.  
  139.             $output .= "</li></ol>";
  140.             $output = str_replace("{image}",$fake_image,$output);
  141.  
  142.             if($related_posts) echo $output;
  143.  
  144.         }
  145.  
  146.         wp_reset_query();
  147.     }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement