list posts under category
-
Hi, I am hoping someone can help me with the basic loop code for an archive.php page (which would also function as the categories page). Ideally I’d like to just produce a list of post titles, or post titles with brief excerpts. Here’s my code — it brings up the first post under the first category, and nothing else:
<?php //get categories, if category has posts, get a post in that category and display it $categories=get_categories(); if ($categories) { foreach($categories as $category) { if ($category->count > 0) { echo '<p>Category <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> has ' . $category->count . ' post(s). </p> '; $number_posts_per_category = -1; // set = -1 to see all posts in the category $posts=get_posts('cat='. $category->term_id .'&showposts='.$number_posts_per_category); 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 ($category->count > 0 } // foreach ($categories } // if ($categories ?>I am using permalinks, if that helps. I am still in the learning phase (obviously); many thanks in advance for any help offered.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘list posts under category’ is closed to new replies.