karolha
Member
Posted 3 years ago #
Hi Friends!
I'm looking for your help how to solve my problem. I'd likie to query posts like this example:
Category1
sub_cat1
post_title
content
Category2
post_title2
content2
post_title3
content3
But it is important to sort list by category. I've tried to hack query posts(); but failed ;).
Cheers!
This will list your categories and three posts from each category:
<?php
$cat_args=array(
'hide_empty' => 0,
'orderby' => 'ID',
'order' => 'ASC'
);
$categories=get_categories($cat_args);
foreach($categories as $category) {
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
$args=array(
'showposts' => 3,
'category__in' => array($category->term_id),
'caller_get_posts'=>1
);
$posts=get_posts($args);
if ($posts) {
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
the_content();
} // foreach($posts
} // if ($posts
} // foreach($categories
?>