1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?php global $post; $cat_ID=array(); $categories = get_the_category(); //get all categories for this post foreach($categories as $category) { array_push($cat_ID,$category->cat_ID); } $args = array( 'orderby' => 'date', 'order' => 'DESC', 'post_type' => 'post', 'numberposts' => 8, 'post__not_in' => array($post->ID), 'category__in' => $cat_ID ); // post__not_in will exclude the post we are displaying $cat_posts = get_posts($args); $out=''; foreach($cat_posts as $cat_post) { $out .= '<li>'; $out .= '<a href="'.get_permalink($cat_post->ID).'" title="'.wptexturize($cat_post->post_title).'">'.wptexturize($cat_post->post_title).'</a></li>'; } $out = '<ul class="cat_post">' . $out . '</ul>'; echo $out; ?> |
When you have clicked into a posts page this will find the category of that post and show others of that category.