<?php
/**
 * Created by PhpStorm.
 * User: marco
 * Date: 25/06/18
 * Time: 13.02
 */
global $post;
$parent_element = '';
$index_element = '';
$bread_crumb_title = null;
$bread_span = '<span style="padding: 0 5px;"> / </span>';
$correzioneInline = '  style="padding-right: 0px!important; margin-right: -5px!important;" ';
if (is_404()) {

    $bread_crumb_title = get_field('titolo_404', 'options');
} else {
    $bread_crumb_title = $post->post_title;


    if ($post->post_type === 'post') {
        $postIndex = get_post_type_archive_link('post');
        $permLink = get_the_permalink($postIndex);
        $index_element = '<li><a href="' . $permLink . '" id="primary-breadcrumb-title">News</a></li>';
    }

    if ($post->post_type === 'page'){
        $parent = wp_get_post_parent_id($post->ID);
        $postIndex = $parent;
        $permLink = get_the_permalink($postIndex);
        if ($parent !== 0) {
            $parent_element = '<span><a href="#" id="primary-breadcrumb-title">' . get_the_title($postIndex) . $bread_span.'</a></span>';
        };

    }

    if ($post->post_type === 'tour_elicottero'){
        $postIndex = get_index_post_ID('tour_elicottero');
        $permLink = get_the_permalink($postIndex);
        $index_element = '<span><a href="' . $permLink . '" id="primary-breadcrumb-title">'.get_the_title($postIndex).$bread_span.'</a></span>';
        $parent = wp_get_post_parent_id($postIndex);

        $postIndex = $parent;
        $permLink = get_the_permalink($postIndex);
        if ($parent !== 0) {
            $parent_element = '<span><a href="#" id="primary-breadcrumb-title">' . get_the_title($postIndex) . $bread_span.'</a></span>';
        };


    }



    if (is_home()) {
        $bread_crumb_title = null;
        $postIndex = get_post_type_archive_link('post');
        $permLink = get_the_permalink($postIndex);
        $index_element = '<li><a href="' . $permLink . '" id="primary-breadcrumb-title">News</a></li>';
    }


}


?>
<section id="site-breadcrumb" class="site-breadcrumb__section" style="overflow: hidden">

    <div class="container">
        <div class="row">
            <div class="col-xs-12">
                <div class="site-breadcrumb__content">
                   <p>
                        <?php echo $parent_element; ?>
                        <?php echo $index_element; ?>
                        <?php if ($bread_crumb_title) : ?>
                            <span><?php echo $bread_crumb_title; ?></span><?php endif; ?>
                    <p>
                </div>
            </div>
        </div>
    </div>
</section>
