Would you like to have a page that lists all your post or custom post categories, while displaying each category’s “sub, related or corresponding” posts listed as hyperlinks – with each post link then linking to their respective single post pages.
There are a couple places where displaying categories with this functionality may be useful for your WordPress website:
– On a sitemap style page… ie: “Browse the five latest posts from each category”
– On a footer
– On a WordPress Advanced Search style page
– WordPress Landing Page
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
$cat_args = array( 'orderby' => 'name', 'order' => 'ASC', 'child_of' => 0 ); $categories = get_categories($cat_args); foreach($categories as $category) { echo '<dl>'; echo '<dt> <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></dt>'; $post_args = array( 'numberposts' => 5, 'category' => $category->term_id ); $posts = get_posts($post_args); foreach($posts as $post) { ?> <dd><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></dd> <?php } echo '<dd class="view-all"> <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>View all posts in ' . $category->name.'</a></dd>'; echo '</dl>'; } |
Find more information here