-
-
Save bezierer/e4761144c50725d05f99d169a57c8807 to your computer and use it in GitHub Desktop.
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
/** | |
* Gets the markup for a featured grid. | |
* | |
* @param array $args Arguments for the grid. | |
* @return string Markup for the feature grid. | |
*/ | |
function wds_comeback_get_featured_grid( $args = array() ) { | |
// bail early if function doesn't exist. | |
if ( ! function_exists( 'wds_comeback_feature_grids' ) ) { | |
return ''; | |
} | |
// setup defaults. | |
$defaults = array( | |
'ID' => wds_comeback_get_featured_grid_id(), | |
); | |
// compile args. | |
$args = wp_parse_args( $args, $defaults ); | |
// bail early if no Grid ID. | |
if ( empty( $args['ID'] ) ) { | |
return ''; | |
} | |
// get grid items from post meta. | |
$featured = wds_comeback_feature_grids()->helpers->get_grid_posts( $args['ID'] ); | |
// bail early if no grid items. | |
if ( empty( $featured ) ) { | |
return ''; | |
} | |
// should the grid display on mobile? | |
$active_mobile = get_field( 'activate_on_mobile', $args['ID'] ); | |
$active_mobile = $active_mobile ? (bool) $active_mobile : false; | |
ob_start(); | |
?> | |
<section class="feature-5-grid<?php echo ( ! $active_mobile ) ? ' mobile-disable' : ''; ?>"> | |
<?php | |
// loop through and add featured posts to the grid. | |
for ( $i = 1; $i <= 5; ++$i ) : | |
// skip if no post. | |
if ( ! isset( $featured[ $i ] ) ) { | |
continue; | |
} | |
// set grid item and post. | |
$grid_item = $featured[ $i ]; | |
?> | |
<div class="grid-item grid-slot-<?php echo esc_attr( $i ); ?>"> | |
<a href="<?php echo esc_url( $grid_item['permalink'] ); ?>" rel="bookmark" <?php post_class( 'featured-post image-as-background featured-cat-' . esc_html( $grid_item['cat_slug'] ) ); ?> | |
<?php if ( ! empty( $grid_item['image'] ) ) : ?>style="background-image: url('<?php echo esc_url( $grid_item['image'] ); ?>')"<?php endif; ?>> | |
<article> | |
<header class="entry-header"> | |
<div class="entry-meta"> | |
<p class="category"> | |
<?php echo esc_html( $grid_item['cat_name'] ); ?> | |
<span class="hilight" <?php echo 'style="background-color: ' . esc_attr( get_field( 'comeback_category_colors', get_the_category( get_the_ID() )[0] ) ) . '"' ?>></span> | |
</p> | |
</div> | |
<h2 class="entry-title"> | |
<?php echo esc_html( $grid_item['title'] ); ?> | |
</h2> | |
</header><!-- .entry-header --> | |
</article><!-- #post-## --> | |
</a><!-- .featured-post --> | |
</div><!-- .grid-slot-x --> | |
<?php | |
endfor; | |
?> | |
</section> | |
<?php | |
return ob_get_clean(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment