I’ve checked this code localy, here is the working snippet:
<?php
$cat_args = array(
'orderby' => 'name',
'order' => 'ASC',
);
$fcategories = get_categories($cat_args);
foreach($fcategories as $fcategory) {
echo '<dl>';
echo '<dt> <a href="' . get_category_link( $fcategory->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $fcategory->name ) . '" ' . '>' . $fcategory->name.'</a></dt>';
$post_args = array(
'posts_per_page' => 1,
'cat' => $fcategory->cat_ID
);
$fposts = query_posts($post_args);
while(have_posts()) : the_post(); ?>
<dd><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></dd>
<?php
echo '<dd class="view-all"> <a href="' . get_category_link( $fcategory->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $fcategory->name ) . '" ' . '>View all posts in ' . $fcategory->name.'</a></dd>';
echo '</dl>';
endwhile;
}
wp_query_reset();
?>
Original answer:
I think the problem might be here:
$post_args = array(
'showposts' => 1,
'category' => $fcategory->cat_ID
);
you’re using category
argument, it should be cat
so try this code:
$post_args = array(
'showposts' => 1,
'cat' => $fcategory->cat_ID
);