Created
October 7, 2016 03:21
-
-
Save anilmeena/2ea201546fef29a4a2cd1e9283b76dc9 to your computer and use it in GitHub Desktop.
Genesis category page template
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 | |
// Create category.php file & put this code | |
/** | |
* Custom Category Template | |
**/ | |
// 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(); | |
?> | |
<?php | |
// Put this code in functions.php file | |
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