WordPress.org

Plugin Directory

Changeset 781181


Ignore:
Timestamp:
10/02/13 05:45:16 (7 months ago)
Author:
greenshady
Message:

Bringing in version 0.6.0 of the plugin.

Location:
breadcrumb-trail
Files:
22 added
5 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • breadcrumb-trail/trunk/breadcrumb-trail.php

    r441019 r781181  
    22/** 
    33 * Plugin Name: Breadcrumb Trail 
    4  * Plugin URI: http://justintadlock.com/archives/2009/04/05/breadcrumb-trail-wordpress-plugin 
    5  * Description: A WordPress plugin that gives you the <code>breadcrumb_trail()</code> template tag to use anywhere in your theme to show a breadcrumb menu. 
    6  * Version: 0.4.1 
     4 * Plugin URI: http://themehybrid.com/plugins/breadcrumb-trail 
     5 * Description: A smart breadcrumb menu plugin embedded with <a href="http://schema.org">Schema.org</a> microdata that can handle variations in site structure more accurately than any other breadcrumb plugin for WordPress. Insert into your theme with the <code>breadcrumb_trail()</code> template tag. 
     6 * Version: 0.6.0 
    77 * Author: Justin Tadlock 
    88 * Author URI: http://justintadlock.com 
    9  * 
    10  * Breadcrumb Trail - A breadcrumb menu script for WordPress. 
    11  * 
    12  * Breadcrumb Trail is a script for showing a breadcrumb trail for any type of page.  It tries to anticipate  
    13  * any type of structure and display the best possible trail that matches your site's permalink structure. 
    14  * While not perfect, it attempts to fill in the gaps left by many other breadcrumb scripts. 
    15  * 
    16  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU  
    17  * General Public License version 2, as published by the Free Software Foundation.  You may NOT assume  
    18  * that you can use any other version of the GPL. 
    19  * 
    20  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  
    21  * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
    22  * 
    23  * @package BreadcrumbTrail 
    24  * @version 0.4.1 
    25  * @author Justin Tadlock <justin@justintadlock.com> 
    26  * @copyright Copyright (c) 2008 - 2011, Justin Tadlock 
    27  * @link http://justintadlock.com/archives/2009/04/05/breadcrumb-trail-wordpress-plugin 
    28  * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
    299 */ 
    3010 
    31 /** 
    32  * Yes, we're localizing the plugin.  This partly makes sure non-English users can use it too.   
    33  * To translate into your language use the breadcrumb-trail-en_EN.po file as as guide.  Poedit  
    34  * is a good tool to for translating. 
    35  * @link http://poedit.net 
    36  * 
    37  * @since 0.1.0 
    38  */ 
    39 load_plugin_textdomain( 'breadcrumb-trail', false, 'breadcrumb-trail' ); 
     11/* Extra check in case the script is being loaded by a theme. */ 
     12if ( !function_exists( 'breadcrumb_trail' ) ) 
     13    require_once( 'inc/breadcrumbs.php' ); 
    4014 
    41 /** 
    42  * Shows a breadcrumb for all types of pages.  This function is formatting the final output of the  
    43  * breadcrumb trail.  The breadcrumb_trail_get_items() function returns the items and this function  
    44  * formats those items. 
    45  * 
    46  * @since 0.1.0 
    47  * @param array $args Mixed arguments for the menu. 
    48  * @return string Output of the breadcrumb menu. 
    49  */ 
    50 function breadcrumb_trail( $args = array() ) { 
    51  
    52     /* Get the textdomain. */ 
    53     $textdomain = breadcrumb_trail_textdomain(); 
    54  
    55     /* Create an empty variable for the breadcrumb. */ 
    56     $breadcrumb = ''; 
    57  
    58     /* Set up the default arguments for the breadcrumb. */ 
    59     $defaults = array( 
    60         'separator' => '/', 
    61         'before' => '<span class="breadcrumb-title">' . __( 'Browse:', $textdomain ) . '</span>', 
    62         'after' => false, 
    63         'front_page' => true, 
    64         'show_home' => __( 'Home', $textdomain ), 
    65         'echo' => true 
    66     ); 
    67  
    68     /* Allow singular post views to have a taxonomy's terms prefixing the trail. */ 
    69     if ( is_singular() ) { 
    70         $post = get_queried_object(); 
    71         $defaults["singular_{$post->post_type}_taxonomy"] = false; 
    72     } 
    73  
    74     /* Apply filters to the arguments. */ 
    75     $args = apply_filters( 'breadcrumb_trail_args', $args ); 
    76  
    77     /* Parse the arguments and extract them for easy variable naming. */ 
    78     $args = wp_parse_args( $args, $defaults ); 
    79  
    80     /* Get the trail items. */ 
    81     $trail = breadcrumb_trail_get_items( $args ); 
    82  
    83     /* Connect the breadcrumb trail if there are items in the trail. */ 
    84     if ( !empty( $trail ) && is_array( $trail ) ) { 
    85  
    86         /* Open the breadcrumb trail containers. */ 
    87         $breadcrumb = '<div class="breadcrumb breadcrumbs"><div class="breadcrumb-trail">'; 
    88  
    89         /* If $before was set, wrap it in a container. */ 
    90         $breadcrumb .= ( !empty( $args['before'] ) ? '<span class="trail-before">' . $args['before'] . '</span> ' : '' ); 
    91  
    92         /* Wrap the $trail['trail_end'] value in a container. */ 
    93         if ( !empty( $trail['trail_end'] ) ) 
    94             $trail['trail_end'] = '<span class="trail-end">' . $trail['trail_end'] . '</span>'; 
    95  
    96         /* Format the separator. */ 
    97         $separator = ( !empty( $args['separator'] ) ? '<span class="sep">' . $args['separator'] . '</span>' : '<span class="sep">/</span>' ); 
    98  
    99         /* Join the individual trail items into a single string. */ 
    100         $breadcrumb .= join( " {$separator} ", $trail ); 
    101  
    102         /* If $after was set, wrap it in a container. */ 
    103         $breadcrumb .= ( !empty( $args['after'] ) ? ' <span class="trail-after">' . $args['after'] . '</span>' : '' ); 
    104  
    105         /* Close the breadcrumb trail containers. */ 
    106         $breadcrumb .= '</div></div>'; 
    107     } 
    108  
    109     /* Allow developers to filter the breadcrumb trail HTML. */ 
    110     $breadcrumb = apply_filters( 'breadcrumb_trail', $breadcrumb, $args ); 
    111  
    112     /* Output the breadcrumb. */ 
    113     if ( $args['echo'] ) 
    114         echo $breadcrumb; 
    115     else 
    116         return $breadcrumb; 
    117 } 
    118  
    119 /** 
    120  * Gets the items for the breadcrumb trail.  This is the heart of the script.  It checks the current page  
    121  * being viewed and decided based on the information provided by WordPress what items should be 
    122  * added to the breadcrumb trail. 
    123  * 
    124  * @since 0.4.0 
    125  * @todo Build in caching based on the queried object ID. 
    126  * @param array $args Mixed arguments for the menu. 
    127  * @return array List of items to be shown in the trail. 
    128  */ 
    129 function breadcrumb_trail_get_items( $args = array() ) { 
    130     global $wp_rewrite; 
    131  
    132     /* Get the textdomain. */ 
    133     $textdomain = breadcrumb_trail_textdomain(); 
    134  
    135     /* Set up an empty trail array and empty path. */ 
    136     $trail = array(); 
    137     $path = ''; 
    138  
    139     /* If $show_home is set and we're not on the front page of the site, link to the home page. */ 
    140     if ( !is_front_page() && $args['show_home'] ) 
    141         $trail[] = '<a href="' . home_url() . '" title="' . esc_attr( get_bloginfo( 'name' ) ) . '" rel="home" class="trail-begin">' . $args['show_home'] . '</a>'; 
    142  
    143     /* If viewing the front page of the site. */ 
    144     if ( is_front_page() ) { 
    145         if ( $args['show_home'] && $args['front_page'] ) 
    146             $trail['trail_end'] = "{$args['show_home']}"; 
    147     } 
    148  
    149     /* If viewing the "home"/posts page. */ 
    150     elseif ( is_home() ) { 
    151         $home_page = get_page( get_queried_object_id() ); 
    152         $trail = array_merge( $trail, breadcrumb_trail_get_parents( $home_page->post_parent, '' ) ); 
    153         $trail['trail_end'] = get_the_title( $home_page->ID ); 
    154     } 
    155  
    156     /* If viewing a singular post (page, attachment, etc.). */ 
    157     elseif ( is_singular() ) { 
    158  
    159         /* Get singular post variables needed. */ 
    160         $post = get_queried_object(); 
    161         $post_id = absint( get_queried_object_id() ); 
    162         $post_type = $post->post_type; 
    163         $parent = absint( $post->post_parent ); 
    164  
    165         /* Get the post type object. */ 
    166         $post_type_object = get_post_type_object( $post_type ); 
    167  
    168         /* If viewing a singular 'post'. */ 
    169         if ( 'post' == $post_type ) { 
    170  
    171             /* If $front has been set, add it to the $path. */ 
    172             $path .= trailingslashit( $wp_rewrite->front ); 
    173  
    174             /* If there's a path, check for parents. */ 
    175             if ( !empty( $path ) ) 
    176                 $trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $path ) ); 
    177  
    178             /* Map the permalink structure tags to actual links. */ 
    179             $trail = array_merge( $trail, breadcrumb_trail_map_rewrite_tags( $post_id, get_option( 'permalink_structure' ), $args ) ); 
    180         } 
    181  
    182         /* If viewing a singular 'attachment'. */ 
    183         elseif ( 'attachment' == $post_type ) { 
    184  
    185             /* If $front has been set, add it to the $path. */ 
    186             $path .= trailingslashit( $wp_rewrite->front ); 
    187  
    188             /* If there's a path, check for parents. */ 
    189             if ( !empty( $path ) ) 
    190                 $trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $path ) ); 
    191  
    192             /* Map the post (parent) permalink structure tags to actual links. */ 
    193             $trail = array_merge( $trail, breadcrumb_trail_map_rewrite_tags( $post->post_parent, get_option( 'permalink_structure' ), $args ) ); 
    194         } 
    195  
    196         /* If a custom post type, check if there are any pages in its hierarchy based on the slug. */ 
    197         elseif ( 'page' !== $post_type ) { 
    198  
    199             /* If $front has been set, add it to the $path. */ 
    200             if ( $post_type_object->rewrite['with_front'] && $wp_rewrite->front ) 
    201                 $path .= trailingslashit( $wp_rewrite->front ); 
    202  
    203             /* If there's a slug, add it to the $path. */ 
    204             if ( !empty( $post_type_object->rewrite['slug'] ) ) 
    205                 $path .= $post_type_object->rewrite['slug']; 
    206  
    207             /* If there's a path, check for parents. */ 
    208             if ( !empty( $path ) ) 
    209                 $trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $path ) ); 
    210  
    211             /* If there's an archive page, add it to the trail. */ 
    212             if ( !empty( $post_type_object->has_archive ) ) 
    213                 $trail[] = '<a href="' . get_post_type_archive_link( $post_type ) . '" title="' . esc_attr( $post_type_object->labels->name ) . '">' . $post_type_object->labels->name . '</a>'; 
    214         } 
    215  
    216         /* If the post type path returns nothing and there is a parent, get its parents. */ 
    217         if ( ( empty( $path ) && 0 !== $parent ) || ( 'attachment' == $post_type ) ) 
    218             $trail = array_merge( $trail, breadcrumb_trail_get_parents( $parent, '' ) ); 
    219  
    220         /* Or, if the post type is hierarchical and there's a parent, get its parents. */ 
    221         elseif ( 0 !== $parent && is_post_type_hierarchical( $post_type ) ) 
    222             $trail = array_merge( $trail, breadcrumb_trail_get_parents( $parent, '' ) ); 
    223  
    224         /* Display terms for specific post type taxonomy if requested. */ 
    225         if ( !empty( $args["singular_{$post_type}_taxonomy"] ) && $terms = get_the_term_list( $post_id, $args["singular_{$post_type}_taxonomy"], '', ', ', '' ) ) 
    226             $trail[] = $terms; 
    227  
    228         /* End with the post title. */ 
    229         $post_title = get_the_title(); 
    230         if ( !empty( $post_title ) ) 
    231             $trail['trail_end'] = $post_title; 
    232     } 
    233  
    234     /* If we're viewing any type of archive. */ 
    235     elseif ( is_archive() ) { 
    236  
    237         /* If viewing a taxonomy term archive. */ 
    238         if ( is_tax() || is_category() || is_tag() ) { 
    239  
    240             /* Get some taxonomy and term variables. */ 
    241             $term = get_queried_object(); 
    242             $taxonomy = get_taxonomy( $term->taxonomy ); 
    243  
    244             /* Get the path to the term archive. Use this to determine if a page is present with it. */ 
    245             if ( is_category() ) 
    246                 $path = get_option( 'category_base' ); 
    247             elseif ( is_tag() ) 
    248                 $path = get_option( 'tag_base' ); 
    249             else { 
    250                 if ( $taxonomy->rewrite['with_front'] && $wp_rewrite->front ) 
    251                     $path = trailingslashit( $wp_rewrite->front ); 
    252                 $path .= $taxonomy->rewrite['slug']; 
    253             } 
    254  
    255             /* Get parent pages by path if they exist. */ 
    256             if ( $path ) 
    257                 $trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $path ) ); 
    258  
    259             /* If the taxonomy is hierarchical, list its parent terms. */ 
    260             if ( is_taxonomy_hierarchical( $term->taxonomy ) && $term->parent ) 
    261                 $trail = array_merge( $trail, breadcrumb_trail_get_term_parents( $term->parent, $term->taxonomy ) ); 
    262  
    263             /* Add the term name to the trail end. */ 
    264             $trail['trail_end'] = single_term_title( '', false ); 
    265         } 
    266  
    267         /* If viewing a post type archive. */ 
    268         elseif ( is_post_type_archive() ) { 
    269  
    270             /* Get the post type object. */ 
    271             $post_type_object = get_post_type_object( get_query_var( 'post_type' ) ); 
    272  
    273             /* If $front has been set, add it to the $path. */ 
    274             if ( $post_type_object->rewrite['with_front'] && $wp_rewrite->front ) 
    275                 $path .= trailingslashit( $wp_rewrite->front ); 
    276  
    277             /* If there's a slug, add it to the $path. */ 
    278             if ( !empty( $post_type_object->rewrite['slug'] ) ) 
    279                 $path .= $post_type_object->rewrite['slug']; 
    280  
    281             /* If there's a path, check for parents. */ 
    282             if ( !empty( $path ) ) 
    283                 $trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $path ) ); 
    284  
    285             /* Add the post type [plural] name to the trail end. */ 
    286             $trail['trail_end'] = $post_type_object->labels->name; 
    287         } 
    288  
    289         /* If viewing an author archive. */ 
    290         elseif ( is_author() ) { 
    291  
    292             /* If $front has been set, add it to $path. */ 
    293             if ( !empty( $wp_rewrite->front ) ) 
    294                 $path .= trailingslashit( $wp_rewrite->front ); 
    295  
    296             /* If an $author_base exists, add it to $path. */ 
    297             if ( !empty( $wp_rewrite->author_base ) ) 
    298                 $path .= $wp_rewrite->author_base; 
    299  
    300             /* If $path exists, check for parent pages. */ 
    301             if ( !empty( $path ) ) 
    302                 $trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $path ) ); 
    303  
    304             /* Add the author's display name to the trail end. */ 
    305             $trail['trail_end'] = get_the_author_meta( 'display_name', get_query_var( 'author' ) ); 
    306         } 
    307  
    308         /* If viewing a time-based archive. */ 
    309         elseif ( is_time() ) { 
    310  
    311             if ( get_query_var( 'minute' ) && get_query_var( 'hour' ) ) 
    312                 $trail['trail_end'] = get_the_time( __( 'g:i a', $textdomain ) ); 
    313  
    314             elseif ( get_query_var( 'minute' ) ) 
    315                 $trail['trail_end'] = sprintf( __( 'Minute %1$s', $textdomain ), get_the_time( __( 'i', $textdomain ) ) ); 
    316  
    317             elseif ( get_query_var( 'hour' ) ) 
    318                 $trail['trail_end'] = get_the_time( __( 'g a', $textdomain ) ); 
    319         } 
    320  
    321         /* If viewing a date-based archive. */ 
    322         elseif ( is_date() ) { 
    323  
    324             /* If $front has been set, check for parent pages. */ 
    325             if ( $wp_rewrite->front ) 
    326                 $trail = array_merge( $trail, breadcrumb_trail_get_parents( '', $wp_rewrite->front ) ); 
    327  
    328             if ( is_day() ) { 
    329                 $trail[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . get_the_time( esc_attr__( 'Y', $textdomain ) ) . '">' . get_the_time( __( 'Y', $textdomain ) ) . '</a>'; 
    330                 $trail[] = '<a href="' . get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ) . '" title="' . get_the_time( esc_attr__( 'F', $textdomain ) ) . '">' . get_the_time( __( 'F', $textdomain ) ) . '</a>'; 
    331                 $trail['trail_end'] = get_the_time( __( 'd', $textdomain ) ); 
    332             } 
    333  
    334             elseif ( get_query_var( 'w' ) ) { 
    335                 $trail[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . get_the_time( esc_attr__( 'Y', $textdomain ) ) . '">' . get_the_time( __( 'Y', $textdomain ) ) . '</a>'; 
    336                 $trail['trail_end'] = sprintf( __( 'Week %1$s', $textdomain ), get_the_time( esc_attr__( 'W', $textdomain ) ) ); 
    337             } 
    338  
    339             elseif ( is_month() ) { 
    340                 $trail[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . get_the_time( esc_attr__( 'Y', $textdomain ) ) . '">' . get_the_time( __( 'Y', $textdomain ) ) . '</a>'; 
    341                 $trail['trail_end'] = get_the_time( __( 'F', $textdomain ) ); 
    342             } 
    343  
    344             elseif ( is_year() ) { 
    345                 $trail['trail_end'] = get_the_time( __( 'Y', $textdomain ) ); 
    346             } 
    347         } 
    348     } 
    349  
    350     /* If viewing search results. */ 
    351     elseif ( is_search() ) 
    352         $trail['trail_end'] = sprintf( __( 'Search results for &quot;%1$s&quot;', $textdomain ), esc_attr( get_search_query() ) ); 
    353  
    354     /* If viewing a 404 error page. */ 
    355     elseif ( is_404() ) 
    356         $trail['trail_end'] = __( '404 Not Found', $textdomain ); 
    357  
    358     /* Allow devs to step in and filter the $trail array. */ 
    359     return apply_filters( 'breadcrumb_trail_items', $trail, $args ); 
    360 } 
    361  
    362 /** 
    363  * Turns %tag% from permalink structures into usable links for the breadcrumb trail.  This feels kind of 
    364  * hackish for now because we're checking for specific %tag% examples and only doing it for the 'post'  
    365  * post type.  In the future, maybe it'll handle a wider variety of possibilities, especially for custom post 
    366  * types. 
    367  * 
    368  * @since 0.4.0 
    369  * @param int $post_id ID of the post whose parents we want. 
    370  * @param string $path Path of a potential parent page. 
    371  * @param array $args Mixed arguments for the menu. 
    372  * @return array $trail Array of links to the post breadcrumb. 
    373  */ 
    374 function breadcrumb_trail_map_rewrite_tags( $post_id = '', $path = '', $args = array() ) { 
    375  
    376     /* Set up an empty $trail array. */ 
    377     $trail = array(); 
    378  
    379     /* Make sure there's a $path and $post_id before continuing. */ 
    380     if ( empty( $path ) || empty( $post_id ) ) 
    381         return $trail; 
    382  
    383     /* Get the post based on the post ID. */ 
    384     $post = get_post( $post_id ); 
    385  
    386     /* If no post is returned, an error is returned, or the post does not have a 'post' post type, return. */ 
    387     if ( empty( $post ) || is_wp_error( $post ) || 'post' !== $post->post_type ) 
    388         return $trail; 
    389  
    390     /* Get the textdomain. */ 
    391     $textdomain = breadcrumb_trail_textdomain(); 
    392  
    393     /* Trim '/' from both sides of the $path. */ 
    394     $path = trim( $path, '/' ); 
    395  
    396     /* Split the $path into an array of strings. */ 
    397     $matches = explode( '/', $path ); 
    398  
    399     /* If matches are found for the path. */ 
    400     if ( is_array( $matches ) ) { 
    401  
    402         /* Loop through each of the matches, adding each to the $trail array. */ 
    403         foreach ( $matches as $match ) { 
    404  
    405             /* Trim any '/' from the $match. */ 
    406             $tag = trim( $match, '/' ); 
    407  
    408             /* If using the %year% tag, add a link to the yearly archive. */ 
    409             if ( '%year%' == $tag ) 
    410                 $trail[] = '<a href="' . get_year_link( get_the_time( 'Y', $post_id ) ) . '" title="' . get_the_time( esc_attr__( 'Y', $textdomain ), $post_id ) . '">' . get_the_time( __( 'Y', $textdomain ), $post_id ) . '</a>'; 
    411  
    412             /* If using the %monthnum% tag, add a link to the monthly archive. */ 
    413             elseif ( '%monthnum%' == $tag ) 
    414                 $trail[] = '<a href="' . get_month_link( get_the_time( 'Y', $post_id ), get_the_time( 'm', $post_id ) ) . '" title="' . get_the_time( esc_attr__( 'F Y', $textdomain ), $post_id ) . '">' . get_the_time( __( 'F', $textdomain ), $post_id ) . '</a>'; 
    415  
    416             /* If using the %day% tag, add a link to the daily archive. */ 
    417             elseif ( '%day%' == $tag ) 
    418                 $trail[] = '<a href="' . get_day_link( get_the_time( 'Y', $post_id ), get_the_time( 'm', $post_id ), get_the_time( 'd', $post_id ) ) . '" title="' . get_the_time( esc_attr__( 'F j, Y', $textdomain ), $post_id ) . '">' . get_the_time( __( 'd', $textdomain ), $post_id ) . '</a>'; 
    419  
    420             /* If using the %author% tag, add a link to the post author archive. */ 
    421             elseif ( '%author%' == $tag ) 
    422                 $trail[] = '<a href="' . get_author_posts_url( $post->post_author ) . '" title="' . esc_attr( get_the_author_meta( 'display_name', $post->post_author ) ) . '">' . get_the_author_meta( 'display_name', $post->post_author ) . '</a>'; 
    423  
    424             /* If using the %category% tag, add a link to the first category archive to match permalinks. */ 
    425             elseif ( '%category%' == $tag && 'category' !== $args["singular_{$post->post_type}_taxonomy"] ) { 
    426  
    427                 /* Get the post categories. */ 
    428                 $terms = get_the_category( $post_id ); 
    429  
    430                 /* Check that categories were returned. */ 
    431                 if ( $terms ) { 
    432  
    433                     /* Sort the terms by ID and get the first category. */ 
    434                     usort( $terms, '_usort_terms_by_ID' ); 
    435                     $term = get_term( $terms[0], 'category' ); 
    436  
    437                     /* If the category has a parent, add the hierarchy to the trail. */ 
    438                     if ( 0 !== $term->parent ) 
    439                         $trail = array_merge( $trail, breadcrumb_trail_get_term_parents( $term->parent, 'category' ) ); 
    440  
    441                     /* Add the category archive link to the trail. */ 
    442                     $trail[] = '<a href="' . get_term_link( $term, 'category' ) . '" title="' . esc_attr( $term->name ) . '">' . $term->name . '</a>'; 
    443                 } 
    444             } 
    445         } 
    446     } 
    447  
    448     /* Return the $trail array. */ 
    449     return $trail; 
    450 } 
    451  
    452 /** 
    453  * Gets parent pages of any post type or taxonomy by the ID or Path.  The goal of this function is to create  
    454  * a clear path back to home given what would normally be a "ghost" directory.  If any page matches the given  
    455  * path, it'll be added.  But, it's also just a way to check for a hierarchy with hierarchical post types. 
    456  * 
    457  * @since 0.3.0 
    458  * @param int $post_id ID of the post whose parents we want. 
    459  * @param string $path Path of a potential parent page. 
    460  * @return array $trail Array of parent page links. 
    461  */ 
    462 function breadcrumb_trail_get_parents( $post_id = '', $path = '' ) { 
    463  
    464     /* Set up an empty trail array. */ 
    465     $trail = array(); 
    466  
    467     /* Trim '/' off $path in case we just got a simple '/' instead of a real path. */ 
    468     $path = trim( $path, '/' ); 
    469  
    470     /* If neither a post ID nor path set, return an empty array. */ 
    471     if ( empty( $post_id ) && empty( $path ) ) 
    472         return $trail; 
    473  
    474     /* If the post ID is empty, use the path to get the ID. */ 
    475     if ( empty( $post_id ) ) { 
    476  
    477         /* Get parent post by the path. */ 
    478         $parent_page = get_page_by_path( $path ); 
    479  
    480         /* If a parent post is found, set the $post_id variable to it. */ 
    481         if ( !empty( $parent_page ) ) 
    482             $post_id = $parent_page->ID; 
    483     } 
    484  
    485     /* If a post ID and path is set, search for a post by the given path. */ 
    486     if ( $post_id == 0 && !empty( $path ) ) { 
    487  
    488         /* Separate post names into separate paths by '/'. */ 
    489         $path = trim( $path, '/' ); 
    490         preg_match_all( "/\/.*?\z/", $path, $matches ); 
    491  
    492         /* If matches are found for the path. */ 
    493         if ( isset( $matches ) ) { 
    494  
    495             /* Reverse the array of matches to search for posts in the proper order. */ 
    496             $matches = array_reverse( $matches ); 
    497  
    498             /* Loop through each of the path matches. */ 
    499             foreach ( $matches as $match ) { 
    500  
    501                 /* If a match is found. */ 
    502                 if ( isset( $match[0] ) ) { 
    503  
    504                     /* Get the parent post by the given path. */ 
    505                     $path = str_replace( $match[0], '', $path ); 
    506                     $parent_page = get_page_by_path( trim( $path, '/' ) ); 
    507  
    508                     /* If a parent post is found, set the $post_id and break out of the loop. */ 
    509                     if ( !empty( $parent_page ) && $parent_page->ID > 0 ) { 
    510                         $post_id = $parent_page->ID; 
    511                         break; 
    512                     } 
    513                 } 
    514             } 
    515         } 
    516     } 
    517  
    518     /* While there's a post ID, add the post link to the $parents array. */ 
    519     while ( $post_id ) { 
    520  
    521         /* Get the post by ID. */ 
    522         $page = get_page( $post_id ); 
    523  
    524         /* Add the formatted post link to the array of parents. */ 
    525         $parents[]  = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_the_title( $post_id ) ) . '">' . get_the_title( $post_id ) . '</a>'; 
    526  
    527         /* Set the parent post's parent to the post ID. */ 
    528         $post_id = $page->post_parent; 
    529     } 
    530  
    531     /* If we have parent posts, reverse the array to put them in the proper order for the trail. */ 
    532     if ( isset( $parents ) ) 
    533         $trail = array_reverse( $parents ); 
    534  
    535     /* Return the trail of parent posts. */ 
    536     return $trail; 
    537 } 
    538  
    539 /** 
    540  * Searches for term parents of hierarchical taxonomies.  This function is similar to the WordPress  
    541  * function get_category_parents() but handles any type of taxonomy. 
    542  * 
    543  * @since 0.3.0 
    544  * @param int $parent_id The ID of the first parent. 
    545  * @param object|string $taxonomy The taxonomy of the term whose parents we want. 
    546  * @return array $trail Array of links to parent terms. 
    547  */ 
    548 function breadcrumb_trail_get_term_parents( $parent_id = '', $taxonomy = '' ) { 
    549  
    550     /* Set up some default arrays. */ 
    551     $trail = array(); 
    552     $parents = array(); 
    553  
    554     /* If no term parent ID or taxonomy is given, return an empty array. */ 
    555     if ( empty( $parent_id ) || empty( $taxonomy ) ) 
    556         return $trail; 
    557  
    558     /* While there is a parent ID, add the parent term link to the $parents array. */ 
    559     while ( $parent_id ) { 
    560  
    561         /* Get the parent term. */ 
    562         $parent = get_term( $parent_id, $taxonomy ); 
    563  
    564         /* Add the formatted term link to the array of parent terms. */ 
    565         $parents[] = '<a href="' . get_term_link( $parent, $taxonomy ) . '" title="' . esc_attr( $parent->name ) . '">' . $parent->name . '</a>'; 
    566  
    567         /* Set the parent term's parent as the parent ID. */ 
    568         $parent_id = $parent->parent; 
    569     } 
    570  
    571     /* If we have parent terms, reverse the array to put them in the proper order for the trail. */ 
    572     if ( !empty( $parents ) ) 
    573         $trail = array_reverse( $parents ); 
    574  
    575     /* Return the trail of parent terms. */ 
    576     return $trail; 
    577 } 
    578  
    579 /** 
    580  * Returns the textdomain used by the script and allows it to be filtered by plugins/themes. 
    581  * 
    582  * @since 0.4.0 
    583  * @returns string The textdomain for the script. 
    584  */ 
    585 function breadcrumb_trail_textdomain() { 
    586     return apply_filters( 'breadcrumb_trail_textdomain', 'breadcrumb-trail' ); 
    587 } 
    588  
    589 ?> 
     15/* Load translation files. Note: Remove this line if packaging with a theme. */ 
     16load_plugin_textdomain( 'breadcrumb-trail', false, 'breadcrumb-trail/languages' ); 
  • breadcrumb-trail/trunk/readme.txt

    r441019 r781181  
    11=== Breadcrumb Trail === 
     2 
    23Contributors: greenshady 
    3 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3687060 
    4 Tags: navigation, menu, breadcrumb, breadcrumbs 
    5 Requires at least: 3.1 
    6 Tested up to: 3.2.1 
    7 Stable tag: 0.4.1 
     4Donate link: http://themehybrid.com/donate 
     5Tags: navigation, menu, breadcrumb, breadcrumbs, microdata, schema 
     6Requires at least: 3.6 
     7Tested up to: 3.7 
     8Stable tag: 0.6.0 
     9License: GPLv2 or later 
     10License URI: http://www.gnu.org/licenses/gpl-2.0.htm 
    811 
    9 An easy-to-use template tag for showing a breadcrumb menu on your site. 
     12A powerful script for adding breadcrumbs to your site that supports Schema.org HTML5-valid microdata. 
    1013 
    1114== Description == 
    1215 
    13 *Breadcrumb Trail* is a plugin that was designed to make it easy to add a breadcrumb menu anywhere you want in your theme. 
     16Breadcrumb Trail is one of the most advanced and robust breadcrumb menu systems available for WordPress.  It started out as a small script for basic blogs but has grown into a system that can handle nearly any site's setup to show the most accurate breadcrumbs for each page. 
    1417 
    15 How is it any better than any other breadcrumb plugin?  Well, it's probably not, to be perfectly honest.  This is just a script I've been building upon for nearly a couple of years that I usually include with my WordPress themes.  I figured I'd package it as a plugin for others to use as well. 
     18### How it works ### 
    1619 
    17 It gives you a new template tag called `breadcrumb_trail()` that you can place anywhere in your template files. 
     20This plugin automatically detects your permalink setup and displays breadcrumbs based off that structure.  Nearly all sites have some sort of hierarchy.  Breadcrumb Trail recognizes that and builds a set of unique breadcrumbs for each page on your site. 
     21 
     22This means that it can also detect custom post types and taxonomies right out of the box.  Whatever you throw at it, it's got a solution. 
     23 
     24### Features ### 
     25 
     26* 5+ years of development and user testing. 
     27* Auto-detects the permalink structure of your site for the most accurate breadcrumbs. 
     28* Hooks for plugin/theme developers to overwrite output. 
     29* Coded with object-oriented programming (OOP) methods to allow developers to extend it for those highly-custom setups. 
     30 
     31### Professional support ### 
     32 
     33If you need professional plugin support from me, the plugin author, you can access the support forums at [Theme Hybrid](http://themehybrid.com/support), which is a professional WordPress help/support site where I handle support for all my plugins and themes for a community of 40,000+ users (and growing). 
    1834 
    1935== Installation == 
    2036 
    21371. Upload `breadcrumb-trail` to the `/wp-content/plugins/` directory. 
    22 1. Activate the plugin through the 'Plugins' menu in WordPress. 
    23 1. Add the appropriate code to your template files as outlined in the `readme.html` file. 
     382. Activate the plugin through the 'Plugins' menu in WordPress. 
     393. Add the `breadcrumb_trail()` template tag to your theme. 
    2440 
    25 More detailed instructions are included in the plugin's `readme.html` file.  It is important to read through that file to properly understand all of the options and how the plugin works. 
     41More detailed instructions are included in the plugin's `readme.md` file. 
    2642 
    2743== Frequently Asked Questions == 
    2844 
    29 = Why was this plugin created? = 
     45### Why was this plugin created? ### 
    3046 
    31 I mostly develop WordPress themes.  Many of my users had a real need for a functional breadcrumb menu without having to find and test a lot of other plugins.  So, I've been developing this script for several years for my theme users. 
     47Many of my theme users had a real need for a functional breadcrumb menu without having to find and test a lot of other plugins.  Therefore, I created a breadcrumbs script for those users.  Eventually, I decided to package it as a plugin and share it with others. 
    3248 
    33 I finally thought it was time to release it publicly so others could enjoy the benefits of this plugin just as my theme users have been. 
     49The plugin is still mostly packaged with themes and is currently being used on millions of WordPress sites. 
    3450 
    35 = What's a breadcrumb menu? = 
     51### What's a breadcrumb menu? ### 
    3652 
    3753Basically, it's a navigational tool.  On many sites, you'll see something that looks like this: 
    3854 
    39 `You are here > Home > Archives > Sub-page` 
     55    You are here: Home > Page > Sub-page > Sub-sub-page 
    4056 
    41 This plugin allows you to easily add this to your site. 
     57This plugin allows you to easily add this type of menu your site. 
    4258 
    43 = How do I add it to my theme? = 
     59### How do I add it to my theme? ### 
    4460 
    45 There are several methods, but in general, you would use this call: 
     61There are several methods, but in general, you would add the following line of code to your theme.  Generally, this goes somewhere near the bottom of your theme's `header.php` template.  However, you can add it anywhere you want in your theme, and it should work. 
    4662 
    47 ` 
    48 <?php if ( function_exists( 'breadcrumb_trail' ) ) breadcrumb_trail(); ?> 
    49 ` 
     63    <?php if ( function_exists( 'breadcrumb_trail' ) ) breadcrumb_trail(); ?> 
    5064 
    51 To see all methods and options, refer to the `readme.html` file included with the plugin download. 
     65To see all methods and options, refer to the `readme.md` file included with the plugin download. 
     66 
     67### Do breadcrumbs show in Google search results? ### 
     68 
     69Yes, breadcrumbs *can* show in Google search results.  The breadcrumbs are coded in a way that all of the major search engines should be able to recognize them.  It is marked up with the appropriate Schema.org properties to make it easier for search engines and other systems to understand. 
     70 
     71With that said, it's still left up to the search provider to actually show the breadcrumbs.  Generally, they do show them. 
     72 
     73Don't expect to see breadcrumbs in your search results on the first day either.  It may take a bit, depending on how often your Web site is crawled. 
     74 
     75### What is Schema.org? Microdata? ### 
     76 
     77[Microdata](http://en.wikipedia.org/wiki/Microdata_(HTML)) is a way to nest metadata into your Web site's pages.  It allows things like search engines and browsers to provide a more useful experience for users.  Microdata provides a way for you to describe the "meaning" (i.e., semantics) of specific items on your site by using a standardized vocabulary. 
     78 
     79[Schema.org](http://schema.org) is a microdata vocabulary.  It is a collaboration by Bing, Google, Yahoo!, and Yandex for creating a set of standardized conventions for using microdata on the Web.  With these standards in place, we can make our Web sites' data more understandable to search engines and browsers while providing a richer experience for users. 
     80 
     81### Does this help with SEO? ### 
     82 
     83Well, it doesn't hurt.  The way I see it, the more meaningful information you provide to search engines, the more likely you are to rank up.  Properly-coded breadcrumbs are just one tool in a gigantic toolbox for building a search-engine optimized site. 
     84 
     85### The breadcrumbs display the wrong data! ### 
     86 
     87This is rare, especially if you put the code in your header template.  However, it can happen on occasion when your theme or another plugin messes with some of WordPress' global variables but doesn't set things back properly after doing whatever it is they're doing. 
     88 
     89There's not really much I can do to correct that within the Breadcrumb Trail plugin.  The only thing I could do is help you fix the theme/plugin causing the issue.  If this happens, you'll need to drop by my [support forums](http://themehybrid.com/support) to get help. 
    5290 
    5391== Screenshots == 
    5492 
    55 There are no screenshots for this plugin. 
     931. Breadcrumbs in Google search results. 
     942. Date-based permalink structure in breadcrumbs. 
     953. Custom post type + taxonomy (portfolio). 
     964. Image attachment of a blog post. 
     97 
     98== Upgrade Notice == 
     99 
     100### Version 0.6.0+ ### 
     101 
     102If upgrading to a version earlier than 0.6.0 to 0.6.0+, you should check the `readme.md` documentation on some of the argument changes if you've been padding custom arguments into the `breadcrumb_trail()` function. 
    56103 
    57104== Changelog == 
    58105 
    59 **Version 0.4.1** 
     106### Version 0.6.0 ### 
     107 
     108* [Schema.org](http://schema.org) support. 
     109* Completely overhauled the entire plugin, rewriting large swathes of code from the ground up.  This version takes an object-oriented approach. 
     110* Blew every other breadcrumb menu script out of the water. 
     111 
     112### Version 0.5.3 ### 
     113 
     114#### Enhancements #### 
     115 
     116* Use `post_type_archive_title()` on post type archives in the trail. 
     117* Add support for taxonomies that have a `$rewrite->slug` that matches a string value for a custom post type's `has_archive` argument. 
     118* Added support for an `archive_title` label for custom post types because we can't use the  `post_type_archive_title()` function on single posts views for the post type. 
     119* Loads of pagination support on both archive-type pages and paged single posts. 
     120* Added support for hierarchical custom post types (get parent posts). 
     121* Added the `network` argument to allow multisite owners to run the trail all the way back to the main site. 
     122 
     123#### Bug fixes #### 
     124 
     125* Only check attachment trail if the attachment has a parent. 
     126* Fixed the issue where the wrong post type archive link matches with a term archive page. 
     127 
     128### Version 0.5.2 ### 
     129 
     130* No friggin' clue. I think I actually skipped version numbers somehow. :) 
     131 
     132### Version 0.5.1 ### 
     133 
     134* Changed license from GPL 2-only to GPL 2+. 
     135* Smarter handling of the `trail-begin` and `trail-end` classes. 
     136* Added `container` argument for wrapping breadcrumbs in a custom HTML element. 
     137* Changed `bbp_get_forum_parent()` to `bbp_get_forum_parent_id()`. 
     138 
     139### Version 0.5.0 ### 
     140 
     141* Use hardcoded strings for the textdomain, not a variable. 
     142* Inline doc updates. 
     143* Added bbPress support. 
     144* Use `single_post_title()` instead of `get_the_title()` for post titles. 
     145 
     146### Version 0.4.1 ### 
    60147 
    61148* Use `get_queried_object()` and `get_queried_object_id()` instead of accessing `$wp_query` directly. 
    62149* Pass `$args` as second parameter in `breadcrumb_trail` hook. 
    63150 
    64 **Version 0.4.0** 
     151### Version 0.4.0 ### 
    65152 
    66153* New function: `breadcrumb_trail_get_items()`, which grabs a list of all the trail items.  This separates the items from the main `breadcrumb_trail()` function. 
     
    70157* Added functionality to handle WP 3.1 post type enhancements. 
    71158 
    72 **Version 0.3.1** 
     159### Version 0.3.1 ### 
    73160 
    74161* Smarter logic in certain areas. 
     
    81168* Added `trail-before` and `trail-after` CSS classes if `$before` or `$after` is set. 
    82169 
    83 **Version 0.3.1** 
     170### Version 0.3.1 ### 
    84171 
    85172* Undefined index error fixes. 
    86173* Fixes for trying to get a property of a non-object. 
    87174 
    88 **Version 0.3** 
     175### Version 0.3.0 ### 
    89176 
    90177* Added more support for custom post types and taxonomies. 
     
    94181* Cleaned up the code. 
    95182 
    96 ** Version 0.2.1 ** 
     183### Version 0.2.1 ### 
    97184 
    98185* Removed and/or added (depending on the case) the extra separator item on sub-categories and date-/time-based breadcrumbs. 
    99186 
    100 ** Version 0.2 ** 
     187### Version 0.2.0 ### 
    101188 
    102189* The title of the "home" page (i.e. posts page) when not the front page is now properly recognized. 
    103190* Cleaned up the code and logic behind the plugin. 
    104191 
    105 **Version 0.1** 
     192### Version 0.1.0 ### 
    106193 
    107194* Launch of the new plugin. 
Note: See TracChangeset for help on using the changeset viewer.