Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $post_type = get_post_type();
- if($post_type == 'post') {
- $categories = get_the_category($post->ID);
- } else {
- $taxonomy = get_object_taxonomies($post_type);
- $categories = get_the_terms( $post->ID, $taxonomy );
- }
- if ($categories) {
- if($post_type == 'post') {
- $category_ids = array();
- foreach($categories as $individual_category) { $category_ids[] = $individual_category->term_id; }
- $args = array( 'category__in' => $category_ids, 'post__not_in' => array($post->ID), 'posts_per_page' => 4, 'ignore_sticky_posts' => 1 );
- } else {
- foreach($categories as $term) { $post_tax = $term->taxonomy; }
- $args = array( 'post_type' => $post_type, "$post_tax" => $term->slug, 'post__not_in' => array($post->ID), 'posts_per_page' => 4);
- }
- $my_query = new wp_query($args);
- if( $my_query->have_posts() ) { ?>
- <div class="t4b_related_tips"> <!-- Related Post Start -->
- <div class="tips-head"><h2>এছাড়াও আপনি পছন্দ করতে পারেন</h2></div>
- <ul><?php
- while ($my_query->have_posts()) : $my_query->the_post(); ?>
- <li><?php
- if ( has_post_thumbnail() ) { ?>
- <div class="tips-image"><a href="<?php the_permalink() ?>"><?php the_post_thumbnail('relatedpost-thumb'); ?></a></div><?php
- } else { ?>
- <div class="tips-image">
- <a href="<?php the_permalink() ?>">
- <img src="<?php echo catch_that_image(); ?>" alt="tips4blog"/>
- </a>
- </div><?php
- } ?>
- <div class="tips-title"><h3><?php echo wp_trim_words( $post->post_title, 15, ' [...]' ); ?></h3></div>
- </li><?php
- endwhile; wp_reset_query(); ?>
- </ul>
- </div> <!-- Related Post End --><?php
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment