Skip to content

Instantly share code, notes, and snippets.

@mcascardi
Last active March 9, 2023 20:56
Show Gist options
  • Save mcascardi/ad7ec62e0cf3f9a710159aaad48116e9 to your computer and use it in GitHub Desktop.
Save mcascardi/ad7ec62e0cf3f9a710159aaad48116e9 to your computer and use it in GitHub Desktop.
<?php
/**
* Show Video
*
* Creates a video element that plays in modal window.
*/
function show_video($type = 'default', $thumb = 0, $post_id = null) {
// Assume this function returns the html for a video player
}
/**
* ACF Learn More Section
*/
function acf_learnmore() {
$html = '';
if (!have_rows('learn_more_section')) {
// No layouts found
return;
}
$layouts = array(
'file_id' => 'learnmore_file',
'video' => 'learnmore_videos',
'external_link' => 'learnmore_external_links',
'relationship' => 'learnmore_relationships'
);
// loop through the rows of data
while (have_rows('learn_more_section')) {
the_row();
$row_layout = get_row_layout();
if ($row_layout == $layouts['file_id']) {
$file_ID = get_sub_field('learnmore_file_id');
$wp_filebase = do_shortcode("[wpfilebase tag='file' id='{$file_ID}' /]");
if (empty($wp_filebase)) {
continue;
}
//Print the shortcode with appended variable
$html .= "<div class='col-md-6'>{$wp_filebase}</div>";
} elseif (get_row_layout() == $layouts['video']) {
$video = get_sub_field('learnmore_video');
$video_html = show_video('button', 0, $video[0]->ID);
if (empty($video_html)) {
continue;
}
$html .= "<div class='col-md-6'>{$video_html}</div>";
} elseif ($row_layout == $layouts['external_link']) {
$link_url = get_sub_field('learnmore_external_link_url');
$link_text = get_sub_field('learnmore_external_link_text');
$link_header = get_sub_field('learnmore_external_link_headline');
$fa = do_shortcode('[fa type="file-o" size="3x"]');
$html .=<<<HTML
<div class="col-md-6">
<div class="media">
<div class="media-left media-middle">
<a href="{$link_url}" target="_blank">{$fa}</a>
</div>
<div class="media-left media-middle">
<h3 class="media-object primary-pink" id="learn-more-link-title">
<a href="{$link_url}" target="_blank">{$link_text}</a>
</h3>
</div>
</div>
</div>
HTML;
} elseif ($row_layout == $layouts['relationship']) {
$post_types = array(
'press-releases' => 'Press Release',
'advisory' => 'Advisory',
'testimonial' => 'Customer Stories',
);
$relationship = get_sub_field('learnmore_relationship');
$url = get_permalink($relationship[0]->ID);
if (in_array($relationship[0]->post_type, array('post', 'page'))) {
$category = get_the_category($relationship[0]->ID);
$post_type = ((!empty($category[0]->cat_name)) ? $category[0]->cat_name : 'Article');
} else {
$post_type = $post_types[$relationship[0]->post_type];
}
$fa = do_shortcode('[fa type="file-o" size="3x"]');
$html .=<<<HTML
<div class="col-md-6">
<div class="media">
<div class="media-left media-middle">
<a href="{$url}"> {$fa} </a>
</div>
<div class="media-left media-middle">
<h3 class="media-object primary-pink" id="learn-more-link-title">
<a href="{$url}">{$relationship[0]->post_title} {$post_type}</a>
</h3>
</div>
</div>
</div>
HTML;
}
}
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment