How can I change related post by category to related post by tags ?
-
How can I change related post by category to related post by tags ?
This is my code, i get it from related-post.php. I am using Wiles theme<?php /** Latest Posts from the same Category * @package wiles **/ global $wiles_option; $categories = get_the_category( $post->ID ); $first_cat =''; if(isset($categories[0]->cat_ID)){ $first_cat = $categories[0]->cat_ID; } $posts_to_show = $wiles_option['single_related_posts_to_show']; $args = array( 'category__in' => array( $first_cat ), 'post__not_in' => array( $post->ID ), 'posts_per_page' => 6, 'orderby' => 'rand' ); $related_posts = get_posts( $args ); if( $related_posts ) { ?> <section class="single-box related-articles"> <h4 class="entry-title"> <?php _e('You May Also Like', 'wiles'); ?> </h4> <?php foreach( $related_posts as $post ): setup_postdata( $post ); ?> <div class="related-article four-col"> <figure class="entry-image"> <a href="<?php the_permalink(); ?>"> <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'small'); } else { ?> <img src="<?php echo get_template_directory_uri(); ?>/images/default-image.png" alt="<?php the_title(); ?>" /> <?php } ?> </a> </figure> <h5><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h5> </div> <?php endforeach; ?> </section><!-- .single-box .related-posts --> <?php } else { return; } wp_reset_postdata(); ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How can I change related post by category to related post by tags ?’ is closed to new replies.