one3dguy

Untitled

Aug 22nd, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. function widget_shortcode() {
  2.  
  3.     global $post;
  4.  
  5. $current_post_type = get_post_type( $post );
  6.  
  7. // The query arguments
  8. $args = array(
  9.     'posts_per_page' => 3,
  10.     'order' => 'DESC',
  11.     'orderby' => 'ID',
  12.     'post_type' => $current_post_type,
  13.     'post__not_in' => array( $post->ID )
  14. );
  15.  
  16. // Create the related query
  17. $rel_query = new WP_Query( $args );
  18.  
  19. // Check if there is any related posts
  20. if( $rel_query->have_posts() ) :
  21. ?>
  22. <h4 class="widget-title toprelated">אולי יעניין אותך גם</h4>
  23.    <div id="related" class="group">
  24.     <ul class="group">
  25. <?php
  26.     // The Loop
  27.     while ( $rel_query->have_posts() ) :
  28.         $rel_query->the_post();
  29. ?>
  30.         <li>
  31.         <a href="<?php the_permalink() ?>" title="<?php the_title() ?>" rel="bookmark">
  32.             <article>
  33.                  <div class="thethumbnail"><?php the_post_thumbnail( array(300, 250) ); ?></div>
  34.                 <h4 class="entry-title"><?php the_title() ?></h4>
  35.              
  36.             </article>
  37.         </a>
  38.         </li>
  39. <?php
  40.     endwhile;
  41. ?>
  42.     </ul><!-- .group -->
  43. </div><!-- #related -->
  44. <?php
  45. endif;
  46.  
  47. // Reset the query
  48. wp_reset_query();
  49.  
  50.  
  51.  }    
  52. add_shortcode( 'related', 'widget_shortcode' );
Advertisement
Add Comment
Please, Sign In to add comment