Last active
August 29, 2015 14:07
-
-
Save graylaurenm/e486d2badf4ae3e2e573 to your computer and use it in GitHub Desktop.
Sharing: Style page_category_index.php for Sample Theme http://oncecoupled.com/2014/06/page-template-list-posts-by-category/#comment-6043
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Template Name: Category Index | |
* Created By: Lauren Gray Designs | |
* URL: http://oncecoupled.com | |
*/ | |
// Remove the loop and replace it with our own | |
remove_action( 'genesis_loop', 'genesis_do_loop' ); | |
add_action( 'genesis_loop', 'LGD_add_archive', 9 ); | |
function LGD_add_archive() { | |
$args = array( | |
'type' => 'post', | |
'orderby' => 'name' | |
); | |
$categories = get_categories( $args ); | |
echo '<div class="entry">'; | |
// List each category | |
foreach($categories as $category) { | |
// Output the cateogry (and link to it) | |
echo '<ul><li><h3><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name . '</a></h3><ul>'; | |
$args = array( | |
'posts_per_page' => -1, | |
'category' => $category->term_id | |
); | |
$myposts = get_posts( $args ); | |
// List the posts in said category | |
foreach ( $myposts as $post ) : setup_postdata( $post ); | |
echo '<li><a href="' . get_permalink( $post->ID ) . '">' . get_the_title( $post->ID ) . '</a></li>'; | |
endforeach; | |
// Close everything up | |
echo '</li></ul></ul><br><br>'; | |
} | |
echo '</div>'; | |
} | |
genesis(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.page-template-page_category_index-php .content { | |
background-color: #fff; | |
margin-bottom: 40px; | |
padding: 50px 60px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment