Tabbed Categories and Posts
-
I’m trying to create a tabbed area with a list of categories which can be clicked to show the posts in each of them.
I’ve tried everything I can find and the latest attempt is this:
<div id="tabs"> <ul class="cat-list"> <?php $cat_args = array( 'orderby' => 'name', 'order' => 'ASC', 'child_of' => 0 ); $categories = get_categories($cat_args); foreach ($categories as $category) { echo '<li> <a href="#' . ( $category->cat_ID ) . '" title="' . sprintf(__("View all posts in %s"), $category->name) . '" ' . '>' . $category->name . '</a></li>'; } echo '</ul> '; foreach ($categories as $category) { echo '<div id="' . ( $category->cat_ID ) . '"><ul class="post-list">'; $post_args = array( 'numberposts' => 20, 'category' => $category->term_id ); echo '<pre>' . print_r($category, 1); $posts = get_posts($post_args); foreach ($posts as $post) { echo '<li><a href="'.the_permalink().'">'.the_title().'</a></li>'; } echo '</ul></div>'; } ?> </div>The categories must be listed in a
- and closed with the posts for each category being listed in a <div> with the id of the category after
Any ideas?
The topic ‘Tabbed Categories and Posts’ is closed to new replies.