-
-
Save gspice/c74245aa612a011ff3be to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Simple Grid helper functions. | |
* | |
* @package SimpleGrid | |
* @subpackage Genesis | |
* @copyright Copyright (c) 2013, Flagship, LLC | |
* @license GPL-2.0+ | |
* @since 2.0.0 | |
*/ | |
// Exit if accessed directly | |
if ( ! defined( 'ABSPATH' ) ) exit; | |
/** | |
* Add post classes for a simple grid loop. | |
* | |
* @since 2.0.0 | |
* @category Grid Loop | |
* @param $classes array An array of classes that should be appended | |
* @param $columns int The number of grid items desired | |
* @return $classes array The grid classes | |
*/ | |
function prefix_simple_grid( $classes, $columns ) { | |
global $wp_query; | |
//* Bail if we don't have a column number or it is invalid. | |
if ( ! isset( $columns ) || ! in_array( $columns, array( 2, 3, 4, 6 ) ) ) { | |
return; | |
} | |
$classes = array( 'simple-grid' ); | |
$column_classes = array( | |
2 => 'one-half', | |
3 => 'one-third', | |
4 => 'one-fourth', | |
6 => 'one-sixth' | |
); | |
$classes[] = $column_classes[absint($columns)]; | |
if( 0 === $wp_query->current_post || 0 === $wp_query->current_post % $columns ) { | |
$classes[] = 'first'; | |
} | |
return $classes; | |
} | |
/** | |
* Set up a grid of one-half elements for use in a post_class filter. | |
* | |
* @since 2.0.0 | |
* @category Grid Loop | |
* @param $classes array An array of the current post classes | |
* @return $classes array The currnt post classes with the grid appended | |
*/ | |
function prefix_one_half_grid( $classes ) { | |
return array_merge( (array) prefix_simple_grid( $classes, 2 ), $classes ); | |
} | |
/** | |
* Set up a grid of one-third elements for use in a post_class filter. | |
* | |
* @since 2.0.0 | |
* @category Grid Loop | |
* @param $classes array An array of the current post classes | |
* @return $classes array The currnt post classes with the grid appended | |
*/ | |
function prefix_one_third_grid( $classes ) { | |
return array_merge( (array) prefix_simple_grid( $classes, 3 ), $classes ); | |
} | |
/** | |
* Set up a grid of one-fourth elements for use in a post_class filter. | |
* | |
* @since 2.0.0 | |
* @category Grid Loop | |
* @param $classes array An array of the current post classes | |
* @return $classes array The currnt post classes with the grid appended | |
*/ | |
function prefix_one_fourth_grid( $classes ) { | |
return array_merge( (array) prefix_simple_grid( $classes, 4 ), $classes ); | |
} | |
/** | |
* Set up a grid of one-sixth elements for use in a post_class filter. | |
* | |
* @since 2.0.0 | |
* @category Grid Loop | |
* @param $classes array An array of the current post classes | |
* @return $classes array The currnt post classes with the grid appended | |
*/ | |
function prefix_one_sixth_grid( $classes ) { | |
return array_merge( (array) prefix_simple_grid( $classes, 6 ), $classes ); | |
} |
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( 'genesis_loop', 'prefix_widget_area_helper' ); | |
/** | |
* Display a widgeted area with a grid loop post class. | |
* | |
* @since 1.0.0 | |
*/ | |
function prefix_widget_area_helper() { | |
add_filter( 'post_class', 'prefix_one_half_grid' ); | |
genesis_widget_area( 'widget-area', array( | |
'before' => '<div class="widget-area">', | |
'after' => '</div> <!-- end .widget-are -->', | |
) ); | |
remove_filter( 'post_class', 'prefix_one_half_grid' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment