• 1.
    <?php
  • 2.
    /*
  • 3.
    Plugin Name: Simple Breadcrumb Navigation
  • 4.
    Plugin URI: http://www.kriesi.at/archives/wordpress-plugin-simple-breadcrumb-navigation
  • 5.
    Description: A simple and very lightweight breadcrumb navigation that covers nested pages and categories
  • 6.
    Version: 1
  • 7.
    Author: Christian "Kriesi" Budschedl
  • 8.
    Author URI: http://www.kriesi.at/
  • 9.
    */
  • 10.
     
  • 11.
    /*
  • 12.
    This program is free software; you can redistribute it and/or modify
  • 13.
    it under the terms of the GNU General Public License as published by
  • 14.
    the Free Software Foundation; either version 3 of the License, or
  • 15.
    (at your option) any later version.
  • 16.
     
  • 17.
    This program is distributed in the hope that it will be useful,
  • 18.
    but WITHOUT ANY WARRANTY; without even the implied warranty of
  • 19.
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  • 20.
    GNU General Public License for more details.
  • 21.
     
  • 22.
    You should have received a copy of the GNU General Public License
  • 23.
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  • 24.
    */
  • 25.
     
  • 26.
    class simple_breadcrumb {
  • 27.
        var $options;
  • 28.
        
  • 29.
        function simple_breadcrumb() {
  • 30.
                $this->options = array(//change this array if you want another output scheme
  • 31.
                'before' => '<span class="breadarrow"> ',
  • 32.
                'after' => ' </span>',
  • 33.
                'delimiter' => '&rarr;'
  • 34.
            );
  • 35.
            $markup = $this->options['before'] . $this->options['delimiter'] . $this->options['after'];
  • 36.
            global $post;
  • 37.
            echo '<p class="breadcrumbs"><a href="' . get_bloginfo('url') . '">';
  • 38.
            //bloginfo('name');
  • 39.
            esc_html_e('Home', 'udesign');
  • 40.
            echo "</a>";
  • 41.
            if (!is_front_page()) {
  • 42.
                echo $markup;
  • 43.
            }
  • 44.
            $output = $this->simple_breadcrumb_case($post);
  • 45.
            echo "<span class='current_crumb'>";
  • 46.
            if (is_page() || is_single()) {
  • 47.
                the_title();
  • 48.
            } else {
  • 49.
                echo $output;
  • 50.
            }
  • 51.
            echo " </span></p>";
  • 52.
        }
  • 53.
     
  • 54.
        function simple_breadcrumb_case($der_post) {
  • 55.
            global $post;
  • 56.
            $markup = $this->options['before'].$this->options['delimiter'].$this->options['after'];
  • 57.
            if (is_page()){
  • 58.
                if($der_post->post_parent) {
  • 59.
                    $my_query = get_post($der_post->post_parent);			 
  • 60.
                    $this->simple_breadcrumb_case($my_query);
  • 61.
                    $link = '<a href="';
  • 62.
                    $link .= get_permalink($my_query->ID);
  • 63.
                    $link .= '">';
  • 64.
                    $link .= ''. get_the_title($my_query->ID) . '</a>'. $markup;
  • 65.
                    echo $link;
  • 66.
                }
  • 67.
                return;			 	
  • 68.
            }
  • 69.
            if(is_single()){
  • 70.
                $category = get_the_category();
  • 71.
                if (is_attachment()){
  • 72.
                    $my_query = get_post($der_post->post_parent);			 
  • 73.
                    $category = get_the_category($my_query->ID);
  • 74.
                    if( $category != null ) {
  • 75.
                    $ID = $category[0]->cat_ID;
  • 76.
                    echo get_category_parents($ID, TRUE, $markup, FALSE );
  • 77.
                    }
  • 78.
                    previous_post_link("%link $markup");
  • 79.
     
  • 80.
                } elseif ( get_post_type( $post ) == 'post' ) {
  • 81.
                    $ID = $category[0]->cat_ID;
  • 82.
                    get_category_parents_for_breadcrumbs( $ID, TRUE, $markup, FALSE );
  • 83.
     
  • 84.
                } else { // custom types
  • 85.
                    echo ucwords( get_post_type( $post ) ) . $markup;
  • 86.
                }
  • 87.
                return;
  • 88.
            }
  • 89.
            if(is_category()){
  • 90.
                $category = get_the_category(); 
  • 91.
                $i = $category[0]->cat_ID;
  • 92.
                $parent = $category[0]-> category_parent;
  • 93.
     
  • 94.
                if($parent > 0 && $category[0]->cat_name == single_cat_title("", false)){
  • 95.
                    echo get_category_parents($parent, TRUE, $markup, FALSE);
  • 96.
                }
  • 97.
                return single_cat_title('',FALSE);
  • 98.
            }
  • 99.
            if (is_tax()) { // taxonomy
  • 100.
                $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
  • 101.
                echo $term->name;
  • 102.
            }
  • 103.
            if(is_author()){
  • 104.
                $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
  • 105.
                return esc_html__('Author: ', 'udesign').$curauth->nickname;
  • 106.
            }
  • 107.
            if(is_tag()){ return esc_html__('Tag: ', 'udesign').single_tag_title('',FALSE); }
  • 108.
            if(is_404()){ return esc_html__('404 - Page not Found', 'udesign'); }
  • 109.
            if(is_search()){ return esc_html__('Search', 'udesign'); }
  • 110.
            if(is_year()){ return get_the_time('Y'); }
  • 111.
            if(is_month()){
  • 112.
                $k_year = get_the_time('Y');
  • 113.
                echo "<a href='".get_year_link($k_year)."'>".$k_year."</a>".$markup;
  • 114.
                return get_the_time('F');
  • 115.
            }
  • 116.
            if(is_day() || is_time()){
  • 117.
                $k_year = get_the_time('Y');
  • 118.
                $k_month = get_the_time('m');
  • 119.
                $k_month_display = get_the_time('F');
  • 120.
                echo "<a href='".get_year_link($k_year)."'>".$k_year."</a>".$markup;
  • 121.
                echo "<a href='".get_month_link($k_year, $k_month)."'>".$k_month_display."</a>".$markup;
  • 122.
                return get_the_time('jS (l)'); 
  • 123.
            }
  • 124.
        }
  • 125.
    }
  • 126.
     
<?php /* Plugin Name: Simple Breadcrumb Navigation Plugin URI: http://www.kriesi.at/archives/wordpress-plugin-simple-breadcrumb-navigation Description: A simple and very lightweight breadcrumb navigation that covers nested pages and categories Version: 1 Author: Christian "Kriesi" Budschedl Author URI: http://www.kriesi.at/ */ /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ class simple_breadcrumb { var $options; function simple_breadcrumb() { $this->options = array(//change this array if you want another output scheme 'before' => '<span class="breadarrow"> ', 'after' => ' </span>', 'delimiter' => '&rarr;' ); $markup = $this->options['before'] . $this->options['delimiter'] . $this->options['after']; global $post; echo '<p class="breadcrumbs"><a href="' . get_bloginfo('url') . '">'; //bloginfo('name'); esc_html_e('Home', 'udesign'); echo "</a>"; if (!is_front_page()) { echo $markup; } $output = $this->simple_breadcrumb_case($post); echo "<span class='current_crumb'>"; if (is_page() || is_single()) { the_title(); } else { echo $output; } echo " </span></p>"; } function simple_breadcrumb_case($der_post) { global $post; $markup = $this->options['before'].$this->options['delimiter'].$this->options['after']; if (is_page()){ if($der_post->post_parent) { $my_query = get_post($der_post->post_parent); $this->simple_breadcrumb_case($my_query); $link = '<a href="'; $link .= get_permalink($my_query->ID); $link .= '">'; $link .= ''. get_the_title($my_query->ID) . '</a>'. $markup; echo $link; } return; } if(is_single()){ $category = get_the_category(); if (is_attachment()){ $my_query = get_post($der_post->post_parent); $category = get_the_category($my_query->ID); if( $category != null ) { $ID = $category[0]->cat_ID; echo get_category_parents($ID, TRUE, $markup, FALSE ); } previous_post_link("%link $markup"); } elseif ( get_post_type( $post ) == 'post' ) { $ID = $category[0]->cat_ID; get_category_parents_for_breadcrumbs( $ID, TRUE, $markup, FALSE ); } else { // custom types echo ucwords( get_post_type( $post ) ) . $markup; } return; } if(is_category()){ $category = get_the_category(); $i = $category[0]->cat_ID; $parent = $category[0]-> category_parent; if($parent > 0 && $category[0]->cat_name == single_cat_title("", false)){ echo get_category_parents($parent, TRUE, $markup, FALSE); } return single_cat_title('',FALSE); } if (is_tax()) { // taxonomy $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->name; } if(is_author()){ $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author')); return esc_html__('Author: ', 'udesign').$curauth->nickname; } if(is_tag()){ return esc_html__('Tag: ', 'udesign').single_tag_title('',FALSE); } if(is_404()){ return esc_html__('404 - Page not Found', 'udesign'); } if(is_search()){ return esc_html__('Search', 'udesign'); } if(is_year()){ return get_the_time('Y'); } if(is_month()){ $k_year = get_the_time('Y'); echo "<a href='".get_year_link($k_year)."'>".$k_year."</a>".$markup; return get_the_time('F'); } if(is_day() || is_time()){ $k_year = get_the_time('Y'); $k_month = get_the_time('m'); $k_month_display = get_the_time('F'); echo "<a href='".get_year_link($k_year)."'>".$k_year."</a>".$markup; echo "<a href='".get_month_link($k_year, $k_month)."'>".$k_month_display."</a>".$markup; return get_the_time('jS (l)'); } } }

Copy Code to Clipboard Raw

Sign-in or Create a Free Account.

Snippi uses Twitter or Facebook to register and create accounts. Registration will enable you to keep track of your snippets. We never spam your timeline or wall. Ever.

Sign-in with Facebook Sign-in with Twitter