list wordpress posts from current category only list wordpress posts from current category only wordpress wordpress

list wordpress posts from current category only


Finally solved it with this code from here: http://www.snilesh.com/resources/wordpress/wordpress-recent-posts-from-current-same-category/

Modified it to include current page and list ascending

<ul id="catnav"><?phpglobal $post;$category = get_the_category($post->ID);$category = $category[0]->cat_ID;$myposts = get_posts(array('numberposts' => 5, 'offset' => 0, 'category__in' => array($category), 'post_status'=>'publish', 'order'=>'ASC' ));foreach($myposts as $post) :setup_postdata($post);?><li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li><?php endforeach; ?><?php wp_reset_query(); ?><li><a href="?p=46">Why Us?</a></li></ul>


<!--Insted Of this-->$myposts = get_posts('numberposts=5&category=1');<!--Use This-->$cat_ID = get_query_var('cat');query_posts('cat='.$cat_ID.'&showposts=5&order=ASC');


$args=array('cat' => get_query_var('cat'),  'orderby' => 'title',  'order' => 'ASC',  'posts_per_page'=>-1,  'caller_get_posts'=>1);$my_query = new WP_Query($args);

It worked for me!