Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save NateJLewis/24b591f344d9511a28fc631bd1705768 to your computer and use it in GitHub Desktop.

Select an option

Save NateJLewis/24b591f344d9511a28fc631bd1705768 to your computer and use it in GitHub Desktop.
<?php
/**
* Template part for the home page.
*
* @package _njl
*/
// check if the flexible content field has rows of data
if( have_rows('content') ):
// loop through the rows of data
while ( have_rows('content') ) : the_row();
// check current row layout
if( get_row_layout() == 'section' ):
$section_title = get_sub_field('section_title');
$section_id = get_sub_field('section_id');
$post_type = get_sub_field('post_type');
?>
<h5 class="display-5 text-xs-center m-y-2"><?php esc_html_e($section_title, '_njl'); ?></h5>
<section id="#<?php echo esc_attr( $section_id ); ?>" class="card-deck home-deck">
<?php
// check if the nested repeater field has rows of data
if( have_rows('featured_posts') ):
// loop through the rows of data
while ( have_rows('featured_posts') ) : the_row();
if( get_row_layout() == 'featured_post_item' ):
if( get_sub_field('post_id') ):
$post_id = get_sub_field('post_id');
$feat_post = get_post( $post_id );
$feat_excerpt = get_excerpt_by_id( $post_id );
$feat_title = $feat_post->post_title;
?>
<article id="post-<?php echo $post_id; ?>" class="card">
<?php
if( get_sub_field('image_or_video') == 'image' ):
$image = get_sub_field('image');
?>
<a class="featured-image-link card-img-top" href="<?php echo esc_url( get_permalink( $post_id ) ); ?>" title="<?php esc_attr_e( $feat_title, '_njl'); ?>" rel="bookmark">
<img class="img-fluid featured-image post_thumbnail" src="<?php echo $image; ?>" alt="<?php esc_attr_e( the_title_attribute( $post_id ), '_njl'); ?>">
</a>
<?php
elseif( get_sub_field('image_or_video') == 'video' ):
$video = get_sub_field('video');
?>
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="<?php echo esc_url( $video )?>" allowfullscreen></iframe>
</div>
<?php
endif;
?>
<div class="entry-content card-block">
<h4 class="card-title">
<a href="<?php echo esc_url( get_permalink( $post_id ) ); ?>"><?php echo get_the_title( $post_id ); ?></a>
</h4>
<?php echo $feat_excerpt;?>
</div>
</article>
<?php
endif;
endif;
endwhile;
endif;
?>
</section>
<?php
endif;
endwhile;
else :
// no layouts found
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment