Created
November 5, 2017 23:16
-
-
Save jamiemitchell/c78bd16f8c822980c5ed27a2779cda30 to your computer and use it in GitHub Desktop.
Entry Grid Shortcode for Genesis
This file contains hidden or 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 Entry Grid Shortcode | |
* | |
* @since 2.0.0 | |
* | |
*/ | |
add_shortcode( 'entry-grid', 'basetheme_entry_grid_shortcode' ); | |
function basetheme_entry_grid_shortcode( $atts ) { | |
global $post; | |
extract( shortcode_atts( array( | |
'limit' => -1, | |
'category' => '', | |
'name' => '', | |
'type' => 'page', | |
'id' => $post->ID | |
), $atts ) ); | |
$args = array( | |
'post_type' => $type, | |
'post_parent' => ($type == 'post') ? '' : $id, | |
'posts_per_page' => $limit, | |
'category_name' => $category, | |
'order' => 'ASC', | |
'orderby' => 'menu_order', | |
'paged' => get_query_var( 'paged' ) | |
); | |
global $wp_query; | |
$loop = new WP_Query( $args ); | |
ob_start(); | |
$i = 0; | |
while ( $loop->have_posts() ) { | |
$loop->the_post(); | |
$classes = ($i % 4 == 0) ? 'one-fourth first' : ' one-fourth'; | |
?> | |
<div id="post-<?php the_ID(); ?>" <?php post_class($classes) ?> | |
<a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'base-theme' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"> | |
<div class="overlay"> | |
<div class="overlay-inner"> | |
<div class="overlay-details"> | |
<?php the_title( '<h4>', '</h4>' );?> | |
</div> | |
</div> | |
</div> | |
<?php if(has_post_thumbnail()) : the_post_thumbnail( 'large' ); endif; ?> | |
</a> | |
</div> | |
<?php | |
$i++; | |
} | |
$output = ob_get_clean(); | |
if ( $output ) { | |
return '<div class="featured-entry-grid">' . $output . '</div>'; | |
} | |
wp_reset_query(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment