What I want to achieve:
I have couple different categories (CatA and CatB) and I would like to list posts by category order.
If I have done it right, It should look like:
CatA
-post 1
-post 2
CatB
-post 3
I use the code below (which gives me incorrect result):
<?php get_header(); ?>
<?php $categories=get_categories('orderby=name&order=ASC');
foreach($categories as $category) {
$args=array('numberposts'=>-1,'category'=>term_id);
$posts=get_posts($args);
if ($posts) {
echo '<p>'. $category->name.'</p> ';
foreach($posts as $post) {
setup_postdata($post); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
} // foreach($posts
} // if ($posts
} // foreach($categories
?>
<?php get_footer(); ?>
The result looks like:
CatA
-post 1
-post 2
-post 3
CatB
-post 1
-post 2
-post 3
Each Category contains all of the posts(which is not what I want) even I have specified the category in $args. I tried to search the resolution in forum, and I found couple solutions but none works.
Can anyone give me some guidance?