-
-
Save wpsmith/5062834 to your computer and use it in GitHub Desktop.
Custom Genesis Category Template with Pagination
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 | |
/** | |
* Custom Category Template | |
* | |
* @package my_child_theme | |
* @since 1.0.0 | |
* @author Travis Smith <[email protected]> | |
* @copyright Copyright (c) 2013, Travis Smith | |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License | |
* @link https://gist.github.com/wpsmith/5062834 | |
* | |
*/ | |
// Remove default loop | |
//remove_action( 'genesis_loop', 'genesis_do_loop' ); | |
function wps_category_loop_args() { | |
return array( | |
'category_name' => get_query_var( 'category_name' ), | |
'paged' => get_query_var( 'paged' ), | |
); | |
} | |
add_action( 'genesis_loop', 'wps_category_do_loop_intro', 5 ); | |
/** | |
* Custom Loop Intro | |
* | |
*/ | |
function wps_category_do_loop_intro() { | |
$args = wp_parse_args( array( 'tag_id' => 12, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'showposts' => 2, ), wps_category_loop_args() ); | |
$query = new WP_Query( $args ); | |
if( $query->have_posts() ): | |
while( $query->have_posts() ): $query->the_post(); global $post; | |
echo '<h1 id="category-title" class="category title">'; | |
the_title(); | |
echo '</h1>'; | |
the_content(); | |
endwhile; | |
// If you want pagination for pt 1 | |
//genesis_posts_nav(); | |
endif; | |
} | |
// Remove Title | |
remove_action( 'genesis_post_title ', 'genesis_do_post_title' ); | |
remove_action( 'genesis_post_content ', 'genesis_do_post_content' ); | |
add_action( 'genesis_post_content', 'wps_category_do_post_content' ); | |
/** | |
* Custom Content | |
* | |
*/ | |
function wps_category_do_post_content() { | |
// Moved this to pre_get_posts | |
//$args = wp_parse_args( array( 'tag__not_in' => 12, 'wps_category_query' => true, ), wps_category_loop_args() ); | |
echo '<div class="category-item">'; | |
the_post_thumbnail('thumbnail'); | |
echo '<div class="post-content">'; | |
printf( '<h2>%s</h2>', get_the_title() ); | |
the_content(); | |
printf( '<a href="%s">%s</a>', get_permalink(), __( 'View Details', 'text-domain' ) ); | |
echo '</div>'; | |
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
<?php | |
add_action( 'pre_get_posts', 'wps_category_pre_get_posts' ); | |
/** | |
* Set posts per page for the main query part | |
* | |
*/ | |
function wps_category_pre_get_posts( $query ) { | |
if ( ! is_admin() && $query->is_main_query() && is_category() ) ) { | |
$query->set( 'posts_per_page', 2 ); | |
$query->set( 'tag__not_in', 12 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks - this worked for me when I removed a closing bracket in line 9 of functions.php