As a quick ‘go to’ reference to all posts in a particular category we wanted to list all the post titles in a numbered list and make them link to the full post.
The links are ordered alphabetically (‘orderby’, ‘title’) in ascending order (‘order’, ‘ASC’) – A’s at start of the list going down alphabetically to Z.
Thanks to Mandi Grant for this – http://www.tilcode.com/wordpress-genesis-framework-showing-a-list-of-post-titles-in-category-view/
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 |
// Change category pages to contain a simple list of your post titles as links - Mandi Grant http://www.tilcode.com/wordpress-genesis-framework-showing-a-list-of-post-titles-in-category-view/ add_action( 'pre_get_posts', 'mjg_show_titles_only_category_pages' ); function mjg_show_titles_only_category_pages( $query ) { if( $query->is_main_query() && $query->is_category() ) { $query->set( 'orderby', 'title' ); $query->set( 'order', 'ASC' ); remove_action( 'genesis_loop', 'genesis_do_loop' ); add_action( 'genesis_loop', 'mjg_custom_loop' ); } } function mjg_custom_loop() { echo '<article class="post type-post status-publish format-standard category-code-snippets entry" itemtype="http://schema.org/CreativeWork" itemscope="">'; echo '<h2>Code Snippets</h2>'; echo '<ul class="category-post-title-list">'; while (have_posts()) : the_post(); ?> <li><a href="<?php the_permalink() ?>"><?php the_title() ?></a></li> <?php endwhile; } |
Line 6 can be edited to include the post category ID (Category 8 in this case). This function will only to be applied to this category page only. Otherwise it will be applied to all category pages.
1 |
if( $query->is_main_query() && $query->is_category( 8 ) ) { |
The working result can be seen here.
Leave a Reply