Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function rm_related_posts($post_id) {
- $tags = wp_get_post_tags($post_id);
- if (!$tags)
- return false;
- // creo un array con i tag di questo articolo
- $tag_ids = array();
- foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
- $args_related =array(
- 'post_type' => 'post',
- 'tag__in' => $tag_ids,
- 'post__not_in' => array($post_id),
- 'posts_per_page'=> 6, // Number of related posts to display.
- );
- $rm_related = new WP_Query($args_related);
- // echo '<pre>';
- // print_r($rm_related);
- // echo '</pre>';
- if ($rm_related->have_posts()) {
- // mostro titoletto
- ?>
- <div class="row row-related-posts">
- <div class="col-md-12">
- <h3><?php _e('Ti potrebbe interessare'); ?></h3>
- </div>
- </div>
- <?php
- $i=0;
- while ($rm_related->have_posts()) : $rm_related->the_post();
- if ($i==0)
- echo '<div class="row">';
- ?>
- <div class="col-md-4">
- <a rel="external" href="<? the_permalink()?>"><?php rm_post_thumbnail(); ?></a>
- <h2><a rel="external" href="<? the_permalink()?>"><?php the_title(); ?></a></h2>
- </div>
- <?php
- if ($i<2) {
- $i++;
- } else {
- // รจ il post "dispari"
- $i=0;
- echo '</div>';
- }
- endwhile;
- // fix
- // chiudo div eventualmente lasciato aperto...
- if ($i==1)
- echo '</div>';
- }
- wp_reset_postdata();
- }
Advertisement
Add Comment
Please, Sign In to add comment