Skip to content

Instantly share code, notes, and snippets.

@timothyjensen
Last active June 4, 2019 19:22
Show Gist options
  • Save timothyjensen/2e9d62ecda9e6dfe9360e142410e479a to your computer and use it in GitHub Desktop.
Save timothyjensen/2e9d62ecda9e6dfe9360e142410e479a to your computer and use it in GitHub Desktop.
Genesis page template. Two rows of posts, with each row being a different category. Three posts per row and no pagination.
<?php
/**
* Template Name: Two Categories in Two Rows
*
*/
//* Remove the standard loop
remove_action( 'genesis_loop', 'genesis_do_loop' );
//* Add classes to display the posts in a grid
add_filter( 'post_class', 'be_archive_post_class' );
//* The loop for the first category
add_action( 'genesis_loop', 'tj_do_custom_loop_one' );
//* The loop for the second category
add_action( 'genesis_loop', 'tj_do_custom_loop_two' );
/**
* Breaks the posts into three columns
*
* @link http://www.billerickson.net/a-better-and-easier-grid-loop/
* @param array $classes An array of post classes.
* @return array $classes An array of post classes.
*/
function be_archive_post_class( $classes ) {
global $wp_query;
$classes[] = 'one-third';
if( 0 == $wp_query->current_post || 0 == $wp_query->current_post % 3 )
$classes[] = 'first';
return $classes;
}
/**
* First custom loop
*
* @param array $args WP Query args
*/
function tj_do_custom_loop_one() {
$args = array(
'category_name' => 'category-3',
'posts_per_page' => 3,
'no_found_rows' => true, //* removes pagination
);
genesis_custom_loop( $args );
}
/**
* Second custom loop
*
* @param array $args WP Query args
*/
function tj_do_custom_loop_two() {
$args = array(
'category_name' => 'category-2',
'posts_per_page' => 3,
'no_found_rows' => true, //* removes pagination
);
genesis_custom_loop( $args );
}
//* Runs the framework
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment