Advertisement
Guest User

Multiple Rows: /includes/related-portfolio-posts.php

a guest
Aug 3rd, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * These functions shows a number of posts related to the currently displayed post.
  5. * Relations are defined by tags: if post tags match, the post will be displayed as related
  6. */
  7.  
  8.  
  9. $columns = 4;
  10. $reladed_posts = false;
  11. $this_id = $post->ID;
  12. $slidecount = 0;
  13. $postcount = ($columns * 3);
  14. $single_class = "one_fourth";
  15.  
  16.  
  17. $tags = wp_get_object_terms( $post->ID, 'portfolio_entries');
  18.  
  19. if ($tags) {
  20.  
  21. $tag_ids = "";
  22. foreach ($tags as $tag ) $tag_ids .= $tag->slug.",";
  23.  
  24. $tag_ids = substr_replace($tag_ids ,"",-1);
  25. $tag_ids = str_replace(" ", "-",$tag_ids);
  26.  
  27. if($tag_ids)
  28. {
  29. $my_query = new WP_Query(array('portfolio_entries'=>$tag_ids, 'showposts'=>$postcount, 'ignore_sticky_posts'=>1, 'orderby'=>'rand', 'post__not_in' => array( $this_id ) ) );
  30.  
  31. if ($my_query->have_posts())
  32. {
  33. $count = 1;
  34. $output = "";
  35.  
  36. $output .= avia_advanced_hr(__('Professional Pathways Profiles','avia_framework'));
  37. $output .= "<div class ='twelve units related-portfolio'>";
  38.  
  39. $output .= "<div class='content_slider autoslide_false'><br />";
  40.  
  41. while ($my_query->have_posts()) : $my_query->the_post();
  42. if($post->ID != $this_id)
  43. {
  44. $reladed_posts = true;
  45. $slidecount ++;
  46.  
  47. if($count == 1)
  48. {
  49. $output .= "<div class='single_slide single_slide_nr_$slidecount'>";
  50. }
  51.  
  52.  
  53. $image = "<span class='related_posts_default_image'>{image}</span>";
  54. $slides = avia_post_meta(get_the_ID(), 'slideshow', true);
  55.  
  56. //check if a preview image is set
  57. if( $slides != "" && !empty( $slides[0]['slideshow_image']) )
  58. {
  59. //check for image or video
  60. if(is_numeric($slides[0]['slideshow_image']))
  61. {
  62. $invisible_image = $image = avia_image_by_id($slides[0]['slideshow_image'], 'portfolio', 'image');
  63. }
  64. else
  65. {
  66. $invisible_image = $image = "<span class='related_posts_default_image related_posts_video'></span>";
  67. }
  68. }
  69.  
  70.  
  71. $output .= "<div class='$single_class relThumb relThumb".$count."'>\n";
  72. $output .= "<a href='".get_permalink()."' target='_blank' class='relThumWrap noLightbox' >\n";
  73. $output .= "<span class='related_image_wrap'>";
  74. $output .= $image;
  75. $output .= "</span>\n";
  76. $output .= "<span class='relThumbTitle'>\n";
  77. $output .= "<strong class='relThumbHeading'>".avia_backend_truncate(get_the_title(), 100)."</strong>\n";
  78. $output .= "</span>\n</a>";
  79. $output .= "</div><!-- end .relThumb -->\n";
  80.  
  81. $count++;
  82.  
  83. if($count == $columns+1)
  84. {
  85. $output .= "</div>";
  86. $count = 1;
  87. }
  88. }
  89. endwhile;
  90.  
  91. if($count != 1) $output .= "</div>";
  92.  
  93. $output .= "</div></div>";
  94. $output = str_replace("{image}",$invisible_image,$output);
  95.  
  96. if($reladed_posts) echo $output;
  97.  
  98. }
  99.  
  100. wp_reset_query();
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement