* @copyright Copyright (c) 2008 - 2015, Justin Tadlock * @link http://themehybrid.com/plugins/breadcrumb-trail * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html */ /** * Shows a breadcrumb for all types of pages. This is a wrapper function for the Breadcrumb_Trail class, * which should be used in theme templates. * * @since 0.1.0 * @access public * @param array $args Arguments to pass to Breadcrumb_Trail. * @return void|string */ function breadcrumb_trail( $args = array() ) { $breadcrumb = apply_filters( 'breadcrumb_trail_object', null, $args ); if ( !is_object( $breadcrumb ) ) $breadcrumb = new best_news_Breadcrumb_Trail( $args ); return $breadcrumb->trail(); } /** * Creates a breadcrumbs menu for the site based on the current page that's being viewed by the user. * * @since 0.6.0 * @access public */ class best_news_Breadcrumb_Trail { /** * Array of items belonging to the current breadcrumb trail. * * @since 0.1.0 * @access public * @var array */ public $items = array(); /** * Arguments used to build the breadcrumb trail. * * @since 0.1.0 * @access public * @var array */ public $args = array(); /** * Array of text labels. * * @since 1.0.0 * @access public * @var array */ public $labels = array(); /** * Array of post types (key) and taxonomies (value) to use for single post views. * * @since 1.0.0 * @access public * @var array */ public $post_taxonomy = array(); /* ====== Magic Methods ====== */ /** * Magic method to use in case someone tries to output the layout object as a string. * We'll just return the trail HTML. * * @since 1.0.0 * @access public * @return string */ public function __toString() { return $this->trail(); } /** * Sets up the breadcrumb trail properties. Calls the `Breadcrumb_Trail::add_items()` method * to creat the array of breadcrumb items. * * @since 0.6.0 * @access public * @param array $args { * @type string $container Container HTML element. nav|div * @type string $before String to output before breadcrumb menu. * @type string $after String to output after breadcrumb menu. * @type bool $show_on_front Whether to show when `is_front_page()`. * @type bool $network Whether to link to the network main site (multisite only). * @type bool $show_title Whether to show the title (last item) in the trail. * @type bool $show_browse Whether to show the breadcrumb menu header. * @type array $labels Text labels. @see Breadcrumb_Trail::set_labels() * @type array $post_taxonomy Taxonomies to use for post types. @see Breadcrumb_Trail::set_post_taxonomy() * @type bool $echo Whether to print or return the breadcrumbs. * } * @return void */ public function __construct( $args = array() ) { $defaults = array( 'container' => '', 'before' => '', 'after' => '', 'show_on_front' => true, 'network' => false, 'show_title' => false, 'show_browse' => false, 'labels' => array(), 'post_taxonomy' => array(), 'echo' => true ); // Parse the arguments with the deaults. $this->args = apply_filters( 'breadcrumb_trail_args', wp_parse_args( $args, $defaults ) ); // Set the labels and post taxonomy properties. $this->set_labels(); $this->set_post_taxonomy(); // Let's find some items to add to the trail! $this->add_items(); } /* ====== Public Methods ====== */ /** * Formats the HTML output for the breadcrumb trail. * * @since 0.6.0 * @access public * @return string */ public function trail() { // Set up variables that we'll need. $breadcrumb = ''; $item_count = count( $this->items ); $item_position = 0; // Connect the breadcrumb trail if there are items in the trail. if ( 0 < $item_count ) { // Add 'browse' label if it should be shown. if ( true === $this->args['show_browse'] ) $breadcrumb .= sprintf( '

%s

', $this->labels['browse'] ); // Open the unordered list. $breadcrumb .= '