Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function widget_shortcode() {
- global $post;
- $current_post_type = get_post_type( $post );
- // The query arguments
- $args = array(
- 'posts_per_page' => 3,
- 'order' => 'DESC',
- 'orderby' => 'ID',
- 'post_type' => $current_post_type,
- 'post__not_in' => array( $post->ID )
- );
- // Create the related query
- $rel_query = new WP_Query( $args );
- // Check if there is any related posts
- if( $rel_query->have_posts() ) :
- ob_start();
- ?>
- <h4 class="widget-title toprelated">אולי יעניין אותך גם</h4>
- <div id="related" class="group">
- <ul class="group">
- <?php
- // The Loop
- while ( $rel_query->have_posts() ) :
- $rel_query->the_post();
- ?>
- <li>
- <a href="<?php the_permalink() ?>" title="<?php the_title() ?>" rel="bookmark">
- <article>
- <div class="thethumbnail"><?php the_post_thumbnail( array(300, 250) ); ?></div>
- <h4 class="entry-title"><?php the_title() ?></h4>
- </article>
- </a>
- </li>
- <?php
- endwhile;
- ?>
- </ul><!-- .group -->
- </div><!-- #related -->
- <?php
- return ob_get_clean();
- endif;
- // Reset the query
- wp_reset_query();
- }
- add_shortcode( 'related', 'widget_shortcode' );
- //run shortcode in text widget
- add_filter('widget_text','do_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement