Skip to content

Instantly share code, notes, and snippets.

@davidperezgar
Created September 4, 2016 14:09
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 davidperezgar/725c344b9ca014b2ab0e587daca7be06 to your computer and use it in GitHub Desktop.
Save davidperezgar/725c344b9ca014b2ab0e587daca7be06 to your computer and use it in GitHub Desktop.
Genesis customize loop
//*Grid Posts
if(is_archive() ){
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
}
add_action( 'genesis_before_entry', 'cmk_grid_posts' );
function cmk_grid_posts() {
global $wp_query;
if ( is_singular() || is_post_type_archive() ) {
return;
}
if ( $wp_query->current_post != 0 || is_paged() || ! is_home() ) {
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
add_filter( 'post_class', 'cmk_grid_post_class' );
add_action( 'genesis_entry_header', 'cmk_posts_grid', 5 );
}
}
function cmk_grid_post_class( $classes ) {
global $wp_query;
if ( $wp_query->is_main_query() ) {
$classes[] = 'grid one-third';
if ( is_home() && ! is_paged() ) {
if ( 0 == ( $wp_query->current_post +2 ) % 3 ) {
$classes[] = 'first';
}
}
elseif ( 0 == $wp_query->current_post % 3 ) {
$classes[] = 'first';
}
}
return $classes;
}
function cmk_posts_grid() {
if ( $image = genesis_get_image( 'format=url&size=thumbnail' ) ) {
printf( '<div class="grid-image"><a href="%s" rel="bookmark"><img src="%s" alt="%s" /></a></div>', get_permalink(), $image, the_title_attribute( 'echo=0' ) );
}
else {
printf( '<div class="grid-image"><a href="%s" rel="bookmark"><img src="%s" alt="%s" /></a></div>', get_permalink(), get_bloginfo( 'stylesheet_directory' ) . '/images/blank.jpg', the_title_attribute( 'echo=0' ) );
}
}
add_action( 'pre_get_posts', 'cmk_front_page_number_posts' );
function cmk_front_page_number_posts( $query ) {
if ( $query->is_home() && $query->is_main_query() && ! is_paged() ) {
$query->set( 'posts_per_page', 9 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment