Skip to content

Instantly share code, notes, and snippets.

@manderly
Last active November 21, 2015 02:35
Show Gist options
  • Save manderly/221dfb3ad9c4db84c44f to your computer and use it in GitHub Desktop.
Save manderly/221dfb3ad9c4db84c44f to your computer and use it in GitHub Desktop.
WordPress custom loop for use with the Genesis framework. Post titles display as a simple vertical list when viewing a category.
//Add this to the bottom of your functions.php file
//Must be using Genesis framework for WordPress
//This code will change your category pages to contain a simple list of your post titles as links
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 '<ul class="category-post-title-list">';
while (have_posts()) : the_post();
?>
<li><a href="<?php the_permalink() ?>"><?php the_title() ?></a></li>
<?php
endwhile;
}
/* Category page specific styling added 10/16/2014 */
.category-post-title-list {
list-style:none;
line-height:2em;
margin-left:20px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment