Skip to content

Instantly share code, notes, and snippets.

@billerickson
Forked from jamiemitchell/taxonomy-product_category.php
Last active December 17, 2015 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save billerickson/5657342 to your computer and use it in GitHub Desktop.
Save billerickson/5657342 to your computer and use it in GitHub Desktop.
Use the main loop, not a custom loop. Customize the loop parameters using 'pre_get_posts' in functions.php.
<?php
/**
* Customize Product Category Query
* @link http://www.billerickson.net/customize-the-wordpress-query/
*/
function be_product_category_query( $query ) {
if( $query->is_main_query() && !is_admin() && $query->is_tax( 'product-category' ) ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
$query->set( 'posts_per_page', '-1' );
}
}
add_action( 'pre_get_posts', 'be_product_category_query' );
<?php
remove_action ('genesis_loop', 'genesis_do_loop');
add_action( 'genesis_loop', 'jm_custom_do_loop' );
function jm_custom_do_loop() {
if( have_posts() ):
echo '<ul>';
while ( have_posts() ) : $loop->the_post();
echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
endwhile;
echo '</ul>';
endif;
}
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment