I'm trying to solve this for a while, but I couldn't get a satisfactory way to get what I want. Maybe it's very simple and I'm just too inexperienced.
I need a way to display all the article titles of the child categories of a given category, like this:
Category "x"
Subcategory 1xa
Post 1xa
Post 2xa
Subcategory 2xb
Post 1xb
Post 2xb
Category "y"
Subcategory 1ya
Post 1ya
Post 2ya
Subcategory 2ab
Post 1yb
Post 2yb
etc
I really can't do this using my limited knowledge. All I could get was child category listing (without the post titles) or a listing of every category, subcategory and posts. I want to get every categories, child categories and the posts come under them( except uncategorized ones), as in the above order. I saw many posts, but didnt got a solution since I'm not well in coding.
Could anyone help me with this? Thank you very much in advance!
<?php
$cat_args = array(
'show_option_all' => '',
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_categories( $cat_args );
foreach( $categories as $category ) {
$args = array(
'showposts' => -1,
'category__in' => array( $category->term_id ),
'caller_get_posts'=> 1
);
$posts = get_posts( $args );
if( $posts ) {
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </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
?>
caller_get_posts
was depreciated in ancient times. Just after the dinosaurs got extinct, it was changed toignore_sticky_posts
. BTW, your code is extremely expensive to run