yan-k
12/12/2014 - 9:23 AM

The breadcrumb for WordPress

The breadcrumb for WordPress

<?php
function the_breadcrumb2($seperator = ' > ', $display_home = true, $home_name = '') {
        
        global $post;

        echo '<ul class="breadcrumbs">';
 
        if (!is_home()) {
            
            if($display_home)
            {
                echo '<li>';
                echo '<a href="'.get_option('home').'">';
                
                if($home_name != '') {
                    echo $home_name;
                }
                else
                {
                    echo get_bloginfo('name');
                }
                
                echo '</a>';
                echo '</li>';

                echo '<li>'.$seperator.'</li>';
            }

            if ( is_category() || is_single() ) 
            {
                $cats = get_the_category( $post->ID );
 
                foreach ( $cats as $cat ) {
                    echo '<li>'.$cat->cat_name.'</li>';
                    echo '<li>'.$seperator.'</li>';
                }
                if ( is_single() ) {
                    echo '<li class="current-breadcrumb">'.get_the_title().'</li>';
                }

            } elseif ( is_page() ) {
 
                if($post->post_parent) {
                    $anc = get_post_ancestors( $post->ID );
                    $anc_link = get_page_link( $post->post_parent );
 
                    foreach ( $anc as $ancestor ) {
                        $output = '<li><a href="'.$anc_link.'">'.get_the_title($ancestor).'</a></li>'.'<li>'.$seperator.'</li>';
                    }

                    echo $output;
                    echo '<li class="current-breadcrumb">'.get_the_title().'</li>';
 
                } else {
                    echo '<li class="current-breadcrumb">'.get_the_title().'</li>';
                }
            }
        }

    elseif (is_tag()) { echo '<li class="current-breadcrumb">'; single_tag_title(); echo '</li>'; }
    elseif (is_day()) { echo '<li class="current-breadcrumb">'; _e('Arkiv: ', 'custom_theme'); the_time('F jS, Y'); echo '</li>';}
    elseif (is_month()) { echo '<li class="current-breadcrumb">'; _e('Arkiv: ', 'custom_theme'); the_time('F, Y'); echo '</li>';}
    elseif (is_year()) { echo '<li class="current-breadcrumb">'; _e('Arkiv: ', 'custom_theme'); the_time('Y'); echo '</li>';}
    elseif (is_author()) { echo '<li class="current-breadcrumb">'; _e('Forfatter Arkiv: ', 'custom_theme'); echo '</li>';}
    elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { echo '<li class="current-breadcrumb">'; _e('Arkiv: ', 'custom_theme'); echo '</li>';;}
    elseif (is_search()) { echo '<li class="current-breadcrumb">'; _e('Søgeresultater: ', 'custom_theme'); echo '</li>'; }

    echo '</ul>';
}
?>