Print categories and posts
<?php
$categories=get_categories('orderby=name&order=ASC');
foreach($categories as $category) {
$posts=get_posts('showposts=-1&cat='. $category->term_id);
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
?>
Hey!
Thanks! I’m not sure where I am supposed to put this code. I’m a newbie 😀
Thanks!
I just tried that code somewhere else and it didn’t seem to do what I wanted. I’m looking to list my posts visually the same way they are on my existing homepage except instead of ordered by date they would be ordered into categories with titles.
That code could be used in place of your existing Loop in your theme’s index.php but you will want to make sure any div’s and the like are honored.
Related:
Stepping Into Templates
Template Hierarchy
well. I still can’t seem to get it. I tried and it just lists them in words and I need them listed in thumbnails.
Thanks nonetheless!