Example #1
0
<?php

get_header();
global $post, $fwe_settings;
$banner = fwe_get_page_banner($post->ID);
?>

<?php 
include locate_template('partials/subpage-banner.php');
?>

<?php 
if (have_posts()) {
    while (have_posts()) {
        the_post();
        ?>
  <?php 
        // Fetch the pages whose stitch_content should be pulled into this one:
        $post_id = get_the_ID();
        $stitches = get_post_meta($post_id, 'stitch_children');
        $stitches = array_filter($stitches, function ($item) {
            return !empty($item);
        });
        $has_stitches = is_array($stitches) && count($stitches);
        $slider_images = get_post_meta($post_id, 'slider_images', true);
        $has_slides = !empty($slider_images) && !empty($slider_images['image'][0][0]);
        ?>

  <?php 
        // This page's content:
        ?>
function fwe_get_page_banner($post_id = null)
{
    if (!$post_id) {
        global $post;
        $post_id = $post->ID;
    }
    $page = get_post($post_id);
    $banner = get_post_meta($post_id, 'banner_image', true);
    $caption = get_post_meta($post_id, 'banner_caption', true);
    if (!$banner) {
        if ($page->post_parent !== 0) {
            return fwe_get_page_banner($page->post_parent);
        } else {
            return null;
        }
    }
    return array('banner' => $banner, 'caption' => $caption);
}