function wpex_breadcrumbs($post_id = '') { // Globals global $wp_query, $wp_rewrite; // Get post id $post_id = $post_id ? $post_id : wpex_get_the_id(); // Define main variables $breadcrumb = ''; $trail = array(); $path = ''; $item_type_scope = 'itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"'; // Default arguments $args = array('separator' => wpex_element('angle_right'), 'front_page' => false, 'echo' => false, 'show_posts_page' => true); // Extract args for easy variable naming. extract($args); /*-----------------------------------------------------------------------------------*/ /* - If not on the front page of the site, link to the home page /*-----------------------------------------------------------------------------------*/ if (!is_front_page()) { $home_title = get_theme_mod('breadcrumbs_home_title') ? get_theme_mod('breadcrumbs_home_title') : __('Home', 'wpex'); $trail[] = '<span ' . $item_type_scope . '> <a href="' . home_url() . '" title="' . esc_attr(get_bloginfo('name')) . '" rel="home" class="trail-begin"> <span itemprop="title">' . $home_title . '</span> </a> </span>'; } /*-----------------------------------------------------------------------------------*/ /* - Front Page /*-----------------------------------------------------------------------------------*/ if (is_front_page()) { if (!$front_page) { $trail = false; } elseif ($show_home) { $trail['trail_end'] = "{$show_home}"; } } elseif (is_home()) { $home_page = get_page($wp_query->get_queried_object_id()); $trail = array_merge($trail, wpex_breadcrumbs_get_parents($home_page->post_parent, '')); $trail['trail_end'] = get_the_title($home_page->ID); } elseif (is_singular()) { // Get singular vars $post = $wp_query->get_queried_object(); $post_id = absint($wp_query->get_queried_object_id()); $post_type = $post->post_type; $parent = $post->post_parent; // If a custom post type, check if there are any pages in its hierarchy based on the slug. if (!in_array($post_type, array('page', 'post', 'product', 'portfolio', 'staff', 'testimonials'))) { $post_type_object = get_post_type_object($post_type); // Add $front to the path if ('post' == $post_type || 'attachment' == $post_type || $post_type_object->rewrite['with_front'] && $wp_rewrite->front) { $path .= trailingslashit($wp_rewrite->front); } // Add slug to $path if (!empty($post_type_object->rewrite['slug'])) { $path .= $post_type_object->rewrite['slug']; } // If $path exists check for parents if (!empty($path)) { $trail = array_merge($trail, wpex_breadcrumbs_get_parents('', $path)); } // If archive page exists add to trail if (!empty($post_type_object->has_archive) && function_exists('get_post_type_archive_link')) { if (!is_singular('product')) { $trail[] = '<span ' . $item_type_scope . ' class="trail-type-archive"> <a href="' . get_post_type_archive_link($post_type) . '" title="' . esc_attr($post_type_object->labels->name) . '"> <span itemprop="title">' . $post_type_object->labels->name . '</span> </a> </span>'; } } } // Add shop page to cart if (is_singular('page') && class_exists('Woocommerce')) { if (is_cart() || is_checkout()) { // Get shop page if (class_exists('Woocommerce') && function_exists('wc_get_page_id')) { $shop_id = wc_get_page_id('shop'); $shop_page_url = get_permalink($shop_id); $shop_title = get_the_title($shop_id); if (function_exists('icl_object_id')) { $shop_title = get_the_title(icl_object_id($shop_id, 'page')); } $shop_title = apply_filters('wpex_bcrums_shop_title', $shop_title); } // Shop page if ($shop_id && $shop_title) { $trail[] = '<span ' . $item_type_scope . ' class="trail-type-archive"> <a href="' . get_permalink($shop_id) . '" title="' . esc_attr($shop_title) . '"> <span itemprop="title">' . $shop_title . '</span> </a> </span>'; } } } // Standard Posts if ('post' == $post_type) { // Main Blog URL if ($blog_page = get_theme_mod('blog_page')) { $blog_url = get_permalink($blog_page); $blog_name = get_the_title($blog_page); if (function_exists('icl_object_id')) { $blog_name = get_the_title(icl_object_id($blog_page, 'page')); } $trail[] = '<span ' . $item_type_scope . ' class="trail-blog-url"> <a href="' . $blog_url . '" title="' . $blog_name . '" itemprop="url"> <span itemprop="title">' . $blog_name . '</span> </a> </span>'; } // 1st Category if (get_theme_mod('breadcrumbs_blog_cat', '1')) { $terms = get_the_terms($post_id, 'category'); if ($terms) { $term = reset($terms); $trail[] = '<span ' . $item_type_scope . ' class="trail-blog-cat"> <a href="' . get_term_link($term) . '" itemprop="url" title="' . $term->name . '"> <span itemprop="title">' . $term->name . '</span> </a> </span>'; } } } // Tribe Events if ('tribe_events' == $post_type && function_exists('tribe_get_events_link')) { $trail[] = '<span ' . $item_type_scope . ' class="trail-portfolio-url"> <a href="' . tribe_get_events_link() . '" title="' . __('All Events', 'wpex') . '"> <span itemprop="title">' . __('All Events', 'wpex') . '</span> </a> </span>'; } // Main Portfolio if ($post_type == 'portfolio') { if ($portfolio_page = get_theme_mod('portfolio_page')) { $portfolio_url = get_permalink($portfolio_page); $portfolio_name = get_the_title($portfolio_page); if (function_exists('icl_object_id')) { $portfolio_name = get_the_title(icl_object_id($portfolio_page, 'page')); } if ($portfolio_url) { $trail[] = '<span ' . $item_type_scope . ' class="trail-portfolio-url"> <a href="' . $portfolio_url . '" title="' . $portfolio_name . '"> <span itemprop="title">' . $portfolio_name . '</span> </a> </span>'; } } // Portfolio 1st Category if (get_theme_mod('breadcrumbs_portfolio_cat', '1') && taxonomy_exists('portfolio_category')) { $terms = get_the_terms($post_id, 'portfolio_category'); if ($terms) { $term = reset($terms); $trail[] = '<span ' . $item_type_scope . ' class="trail-portfolio-cat"> <a href="' . get_term_link($term) . '" itemprop="url" title="' . $term->name . '"> <span itemprop="title">' . $term->name . '</span> </a> </span>'; } } } // Main Staff if ($post_type == 'staff') { // Display staff page if ($staff_page = get_theme_mod('staff_page')) { $staff_url = get_permalink($staff_page); $staff_name = get_the_title($staff_page); if (function_exists('icl_object_id')) { $staff_name = get_the_title(icl_object_id($staff_page, 'page')); } if ($staff_url) { $trail[] = '<span ' . $item_type_scope . ' class="trail-staff-url"> <a href="' . $staff_url . '" title="' . $staff_name . '"> <span itemprop="title">' . $staff_name . '</span> </a> </span>'; } } // Staff 1st Category if (get_theme_mod('breadcrumbs_staff_cat', '1') && taxonomy_exists('staff_category')) { $terms = get_the_terms($post_id, 'staff_category'); if ($terms) { $term = reset($terms); $trail[] = '<span ' . $item_type_scope . '> <a href="' . get_term_link($term) . '" itemprop="url" title="' . $term->name . '"> <span itemprop="title">' . $term->name . '</span> </a> </span>'; } } } // Main Testimonials if ($post_type == 'testimonials') { // Display testimonials page if ($testimonials_page = get_theme_mod('testimonials_page')) { $testimonials_url = get_permalink($testimonials_page); $testimonials_name = get_the_title($testimonials_page); if (function_exists('icl_object_id')) { $testimonials_name = get_the_title(icl_object_id($testimonials_page, 'page')); } if ($testimonials_url) { $trail[] = '<span ' . $item_type_scope . ' class="trail-testimonials-url"> <a href="' . $testimonials_url . '" title="' . $testimonials_name . '"> <span itemprop="title">' . $testimonials_name . '</span> </a> </span>'; } } // Testimonials 1st Category if (get_theme_mod('breadcrumbs_testimonials_cat', '1') && taxonomy_exists('testimonials_category')) { $terms = get_the_terms($post_id, 'testimonials_category'); if ($terms) { $term = reset($terms); $trail[] = '<span ' . $item_type_scope . '> <a href="' . get_term_link($term) . '" itemprop="url" title="' . $term->name . '"> <span itemprop="title">' . $term->name . '</span> </a> </span>'; } } } // Products if (is_singular('product') && class_exists('Woocommerce')) { // Globals global $woocommerce; // Get shop page if (class_exists('Woocommerce') && function_exists('wc_get_page_id')) { $shop_id = wc_get_page_id('shop'); $shop_page_url = get_permalink($shop_id); $shop_title = get_the_title($shop_id); if (function_exists('icl_object_id')) { $shop_title = get_the_title(icl_object_id($shop_id, 'page')); } $shop_title = apply_filters('wpex_bcrums_shop_title', $shop_title); } // Shop page if ($shop_id && $shop_title) { $trail[] = '<span ' . $item_type_scope . ' class="trail-type-archive"> <a href="' . get_permalink($shop_id) . '" title="' . esc_attr($shop_title) . '"> <span itemprop="title">' . $shop_title . '</span> </a> </span>'; } // Cart page if (sizeof($woocommerce->cart->cart_contents) > 0) { $cart_id = wc_get_page_id('cart'); $cart_title = get_the_title($cart_id); if ($cart_id) { $trail[] = '<span ' . $item_type_scope . ' class="trail-type-archive"> <a href="' . get_permalink($cart_id) . '" title="' . esc_attr($cart_title) . '"> <span itemprop="title">' . $cart_title . '</span> </a> </span>'; } } } // If the post type path returns nothing and there is a parent, get its parents. if (empty($path) && 0 !== $parent || 'attachment' == $post_type) { $trail = array_merge($trail, wpex_breadcrumbs_get_parents($parent, '')); } // End trail with post title $post_title = get_the_title($post_id); if (!empty($post_title)) { if ($trim_title = get_theme_mod('breadcrumbs_title_trim', '4')) { $post_title = wp_trim_words($post_title, $trim_title); $trail['trail_end'] = $post_title; } else { $trail['trail_end'] = $post_title; } } } elseif (is_archive()) { // Add cart to shop if (function_exists('is_shop') && is_shop()) { global $woocommerce; if (sizeof($woocommerce->cart->cart_contents) > 0) { $cart_id = wc_get_page_id('cart'); $cart_title = get_the_title($cart_id); if ($cart_id) { $trail[] = '<span ' . $item_type_scope . ' class="trail-type-archive"> <a href="' . get_permalink($cart_id) . '" title="' . esc_attr($cart_title) . '"> <span itemprop="title">' . $cart_title . '</span> </a> </span>'; } } } // Topics if (is_post_type_archive('topic')) { $forums_link = get_post_type_archive_link('forum'); $forum_obj = get_post_type_object('forum'); $forum_name = $forum_obj->labels->name; if ($forums_link) { $trail[] = '<span ' . $item_type_scope . '><a href="' . $forums_link . '" title="' . $forum_name . '">' . $forum_name . '</a></span>'; } } /*-----------------------------------------------------------------------------------*/ /* - Taxonomies /*-----------------------------------------------------------------------------------*/ if (is_tax() || is_category() || is_tag()) { // Get some taxonomy variables $term = $wp_query->get_queried_object(); $taxonomy = get_taxonomy($term->taxonomy); // Link to main portfolio page if (function_exists('wpex_is_portfolio_tax') && wpex_is_portfolio_tax() && ($portfolio_page = get_theme_mod('portfolio_page'))) { $portfolio_url = get_permalink($portfolio_page); $portfolio_name = get_the_title($portfolio_page); if (function_exists('icl_object_id')) { $portfolio_name = get_the_title(icl_object_id($portfolio_page, 'page')); } if ($portfolio_url) { $trail[] = '<span ' . $item_type_scope . ' class="trail-portfolio-url"> <a href="' . $portfolio_url . '" title="' . $portfolio_name . '"> <span itemprop="title">' . $portfolio_name . '</span> </a> </span>'; } } // Link to main staff page if (function_exists('wpex_is_staff_tax') && wpex_is_staff_tax() && ($staff_page = get_theme_mod('staff_page'))) { $staff_url = get_permalink($staff_page); $staff_name = get_the_title($staff_page); if (function_exists('icl_object_id')) { $staff_name = get_the_title(icl_object_id($staff_page, 'page')); } if ($staff_url) { $trail[] = '<span ' . $item_type_scope . ' class="trail-staff-url"> <a href="' . $staff_url . '" title="' . $staff_name . '"> <span itemprop="title">' . $staff_name . '</span> </a> </span>'; } } // Testimonials Tax if (function_exists('wpex_is_testimonials_tax') && wpex_is_testimonials_tax() && ($testimonials_page = get_theme_mod('testimonials_page'))) { $testimonials_url = get_permalink($testimonials_page); $testimonials_name = get_the_title($testimonials_page); if (function_exists('icl_object_id')) { $testimonials_name = get_the_title(icl_object_id($testimonials_page, 'page')); } if ($testimonials_url) { $trail[] = '<span ' . $item_type_scope . ' class="trail-testimonials-url"> <a href="' . $testimonials_url . '" title="' . $testimonials_name . '"> <span itemprop="title">' . $testimonials_name . '</span> </a> </span>'; } } // Woo Product Tax if (function_exists('wpex_is_woo_tax') && wpex_is_woo_tax()) { // Get shop page if (class_exists('Woocommerce') && function_exists('wc_get_page_id')) { $shop_id = wc_get_page_id('shop'); $shop_page_url = get_permalink($shop_id); $shop_title = get_the_title($shop_id); if (function_exists('icl_object_id')) { $shop_title = get_the_title(icl_object_id($shop_id, 'page')); } $shop_title = apply_filters('wpex_bcrums_shop_title', $shop_title); } if ($shop_page_url && $shop_title) { $trail[] = '<span ' . $item_type_scope . ' class="trail-shop"> <a href="' . $shop_page_url . '" title="' . $shop_title . '" itemprop="url"> <span itemprop="title">' . $shop_title . '</span> </a> </span>'; } } // Display main blog page on Categories & archives if (is_category() || is_tag()) { if ($blog_page = get_theme_mod('blog_page')) { $blog_url = get_permalink($blog_page); $blog_name = get_the_title($blog_page); if (function_exists('icl_object_id')) { $blog_name = get_the_title(icl_object_id($blog_page, 'page')); } $trail[] = '<span ' . $item_type_scope . ' class="trail-blog-url"> <a href="' . $blog_url . '" title="' . $blog_name . '" itemprop="url"> <span itemprop="title">' . $blog_name . '</span> </a> </span>'; } } // Get the path to the term archive. Use this to determine if a page is present with it. if (is_category()) { $path = get_option('category_base'); } elseif (is_tag()) { $path = get_option('tag_base'); } else { if ($taxonomy->rewrite['with_front'] && $wp_rewrite->front) { $path = trailingslashit($wp_rewrite->front); } $path .= $taxonomy->rewrite['slug']; } // Get parent pages if they exist if ($path) { $trail = array_merge($trail, wpex_breadcrumbs_get_parents('', $path)); } // Add term parents if (is_taxonomy_hierarchical($term->taxonomy) && $term->parent) { $trail = array_merge($trail, wpex_breadcrumbs_get_term_parents($term->parent, $term->taxonomy)); } // Add term name to trail end $trail['trail_end'] = $term->name; } elseif (is_post_type_archive()) { // Get post type object $post_type_object = get_post_type_object(get_query_var('post_type')); // Add $front to $path if ($post_type_object->rewrite['with_front'] && $wp_rewrite->front) { $path .= trailingslashit($wp_rewrite->front); } // Add slug to 4path if (!empty($post_type_object->rewrite['archive'])) { $path .= $post_type_object->rewrite['archive']; } // If patch exists check for parents if (!empty($path)) { $trail = array_merge($trail, wpex_breadcrumbs_get_parents('', $path)); } // Add post type name to trail end $trail['trail_end'] = $post_type_object->labels->name; } elseif (is_author()) { /* If $front has been set, add it to $path. */ if (!empty($wp_rewrite->front)) { $path .= trailingslashit($wp_rewrite->front); } /* If an $author_base exists, add it to $path. */ if (!empty($wp_rewrite->author_base)) { $path .= $wp_rewrite->author_base; } /* If $path exists, check for parent pages. */ if (!empty($path)) { $trail = array_merge($trail, wpex_breadcrumbs_get_parents('', $path)); } /* Add the author's display name to the trail end. */ $trail['trail_end'] = get_the_author_meta('display_name', get_query_var('author')); } elseif (is_time()) { if (get_query_var('minute') && get_query_var('hour')) { $trail['trail_end'] = get_the_time(__('g:i a', 'wpex')); } elseif (get_query_var('minute')) { $trail['trail_end'] = sprintf(__('Minute %1$s', 'wpex'), get_the_time(__('i', 'wpex'))); } elseif (get_query_var('hour')) { $trail['trail_end'] = get_the_time(__('g a', 'wpex')); } } elseif (is_date()) { // If $front is set check for parents if ($wp_rewrite->front) { $trail = array_merge($trail, wpex_breadcrumbs_get_parents('', $wp_rewrite->front)); } if (is_day()) { $trail[] = '<a href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time(esc_attr__('Y', 'wpex')) . '">' . get_the_time(__('Y', 'wpex')) . '</a>'; $trail[] = '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '" title="' . get_the_time(esc_attr__('F', 'wpex')) . '">' . get_the_time(__('F', 'wpex')) . '</a>'; $trail['trail_end'] = get_the_time(__('j', 'wpex')); } elseif (get_query_var('w')) { $trail[] = '<a href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time(esc_attr__('Y', 'wpex')) . '">' . get_the_time(__('Y', 'wpex')) . '</a>'; $trail['trail_end'] = sprintf(__('Week %1$s', 'wpex'), get_the_time(esc_attr__('W', 'wpex'))); } elseif (is_month()) { $trail[] = '<a href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time(esc_attr__('Y', 'wpex')) . '">' . get_the_time(__('Y', 'wpex')) . '</a>'; $trail['trail_end'] = get_the_time(__('F', 'wpex')); } elseif (is_year()) { $trail['trail_end'] = get_the_time(__('Y', 'wpex')); } } } elseif (is_search()) { $trail['trail_end'] = sprintf(__('Search results for "%1$s"', 'wpex'), esc_attr(get_search_query())); } elseif (is_404()) { $trail['trail_end'] = get_theme_mod('error_page_title') ? get_theme_mod('error_page_title') : __('404 Not Found', 'wpex'); } elseif (function_exists('tribe_is_month') && tribe_is_month()) { $trail['trail_end'] = __('Events Calendar', 'wpex'); } /*-----------------------------------------------------------------------------------*/ /* - Create and return the breadcrumbs /*-----------------------------------------------------------------------------------*/ if ($trail && is_array($trail)) { $classes = 'site-breadcrumbs clr'; if ($breadcrumbs_position = get_theme_mod('breadcrumbs_position')) { $classes .= ' position-' . $breadcrumbs_position; } // Open Breadcrumbs $breadcrumb = '<nav class="' . $classes . '"><div class="breadcrumb-trail">'; // Seperator HTML $separator = '<span class="sep">' . $separator . '</span>'; // Join all trail items into a string $breadcrumb .= implode($separator, $trail); // Close breadcrumbs $breadcrumb .= '</div></nav>'; } // Return the breadcrumbs trail return $breadcrumb; }
function wpex_breadcrumbs($args = array()) { global $wp_query, $wp_rewrite; /*woocommerce*/ if (class_exists('Woocommerce')) { $shop_page_url = get_permalink(woocommerce_get_page_id('shop')); $shop_title = __('Shop', 'wpex'); $shop_title = apply_filters('wpex_bcrums_shop_title', $shop_title); } /* Admin settings */ $blog_url = wpex_option('blog_url'); $portfolio_url = wpex_option('portfolio_url'); $staff_url = wpex_option('staff_url'); $testimonials_url = wpex_option('testimonials_url'); /* Translations */ $blog_name = __('Blog', 'wpex'); $blog_name = apply_filters('wpex_blog_name', $blog_name); $portfolio_name = wpex_option('portfolio_labels', __('Portfolio', 'wpex')); $testimonials_name = wpex_option('testimonials_labels', __('Testimonials', 'wpex')); $staff_name = wpex_option('staff_labels', __('Staff', 'wpex')); /* Create an empty variable for the breadcrumb. */ $breadcrumb = ''; /* Create an empty array for the trail. */ $trail = array(); $path = ''; /* Set up the default arguments for the breadcrumb. */ $defaults = array('separator' => '<span class="fa fa-angle-right"></span>', 'before' => '', 'after' => false, 'front_page' => true, 'show_home' => __('Home', 'wpex'), 'echo' => false, 'show_posts_page' => true); /* Allow singular post views to have a taxonomy's terms prefixing the trail. */ if (is_singular()) { $defaults["singular_{$wp_query->post->post_type}_taxonomy"] = false; } /* Apply filters to the arguments. */ $args = apply_filters('wpex_breadcrumbs_args', $args); /* Parse the arguments and extract them for easy variable naming. */ extract(wp_parse_args($args, $defaults)); /* If $show_home is set and we're not on the front page of the site, link to the home page. */ if (!is_front_page() && $show_home) { $trail[] = '<a href="' . home_url() . '" title="' . esc_attr(get_bloginfo('name')) . '" rel="home" class="trail-begin">' . $show_home . '</a>'; } /* If viewing the front page of the site. */ if (is_front_page()) { if (!$front_page) { $trail = false; } elseif ($show_home) { $trail['trail_end'] = "{$show_home}"; } } elseif (is_home()) { $home_page = get_page($wp_query->get_queried_object_id()); $trail = array_merge($trail, wpex_breadcrumbs_get_parents($home_page->post_parent, '')); $trail['trail_end'] = get_the_title($home_page->ID); } elseif (is_singular()) { /* Get singular post variables needed. */ $post = $wp_query->get_queried_object(); $post_id = absint($wp_query->get_queried_object_id()); $post_type = $post->post_type; $parent = $post->post_parent; /* If a custom post type, check if there are any pages in its hierarchy based on the slug. */ if ('page' !== $post_type && 'post' !== $post_type) { $post_type_object = get_post_type_object($post_type); /* If $front has been set, add it to the $path. */ if ('post' == $post_type || 'attachment' == $post_type || $post_type_object->rewrite['with_front'] && $wp_rewrite->front) { $path .= trailingslashit($wp_rewrite->front); } /* If there's a slug, add it to the $path. */ if (!empty($post_type_object->rewrite['slug'])) { $path .= $post_type_object->rewrite['slug']; } /* If there's a path, check for parents. */ if (!empty($path)) { $trail = array_merge($trail, wpex_breadcrumbs_get_parents('', $path)); } /* If there's an archive page, add it to the trail. */ if (!empty($post_type_object->has_archive) && function_exists('get_post_type_archive_link')) { if (!is_singular('product')) { $trail[] = '<a href="' . get_post_type_archive_link($post_type) . '" title="' . esc_attr($post_type_object->labels->name) . '">' . $post_type_object->labels->name . '</a>'; } } } /*add shop page to cart*/ if (is_singular('page') && class_exists('Woocommerce')) { if (is_cart() || is_checkout()) { $trail[] = '<a href="' . $shop_page_url . '" title="' . $shop_title . '">' . $shop_title . '</a>'; } } /* Display category if('post' == $post_type) { $category = get_the_category(); $ID = $category[0]->cat_ID; $parents = get_category_parents($ID, TRUE, '$$$', FALSE ); $parents = explode("$$$", $parents); foreach ($parents as $parent_item) { if($parent_item) $trail[] = $parent_item; } } */ // Main Blog if ('post' == $post_type && $blog_url) { $trail[] = '<a href="' . $blog_url . '" title="' . $blog_name . '">' . $blog_name . '</a>'; } // Main Portfolio if ($post_type == 'portfolio' && $portfolio_url) { $trail[] = '<a href="' . $portfolio_url . '" title="' . $portfolio_name . '">' . $portfolio_name . '</a>'; } // Main Staff if ($post_type == 'staff' && $staff_url) { $trail[] = '<a href="' . $staff_url . '" title="' . $staff_name . '">' . $staff_name . '</a>'; } // Main Testimonials if ($post_type == 'testimonials' && $testimonials_url) { $trail[] = '<a href="' . $testimonials_url . '" title="' . $testimonials_name . '">' . $testimonials_name . '</a>'; } /* If the post type path returns nothing and there is a parent, get its parents. */ if (empty($path) && 0 !== $parent || 'attachment' == $post_type) { $trail = array_merge($trail, wpex_breadcrumbs_get_parents($parent, '')); } /* Toggle the display of the posts page on single blog posts. */ if ('post' == $post_type && $show_posts_page == true && 'page' == get_option('show_on_front')) { $posts_page = get_option('page_for_posts'); if ($posts_page != '' && is_numeric($posts_page)) { $trail = array_merge($trail, wpex_breadcrumbs_get_parents($posts_page, '')); } } /* Display terms for specific post type taxonomy if requested. */ if (isset($args["singular_{$post_type}_taxonomy"]) && ($terms = get_the_term_list($post_id, $args["singular_{$post_type}_taxonomy"], '', ', ', ''))) { $trail[] = $terms; } /* End with the post title. */ $post_title = get_the_title($post_id); // Force the post_id to make sure we get the correct page title. if (!empty($post_title)) { $post_title_length = str_word_count($post_title); if ($post_title_length > 8) { $post_title = wp_trim_words($post_title, '4'); $trail['trail_end'] = $post_title; } else { $trail['trail_end'] = $post_title; } } } elseif (is_archive()) { /* If viewing a taxonomy term archive. */ if (is_tax() || is_category() || is_tag()) { /* Get some taxonomy and term variables. */ $term = $wp_query->get_queried_object(); $taxonomy = get_taxonomy($term->taxonomy); // Portfolio Tax if (is_tax('portfolio_category') && $portfolio_url) { $trail[] = '<a href="' . $portfolio_url . '" title="' . $portfolio_name . '">' . $portfolio_name . '</a>'; } if (is_tax('portfolio_tag') && $portfolio_url) { $trail[] = '<a href="' . $portfolio_url . '" title="' . $portfolio_name . '">' . $portfolio_name . '</a>'; } // Staff Tax if (is_tax('staff_category') && $staff_url) { $trail[] = '<a href="' . $staff_url . '" title="' . $staff_name . '">' . $staff_name . '</a>'; } if (is_tax('staff_tag') && $staff_url) { $trail[] = '<a href="' . $staff_url . '" title="' . $staff_name . '">' . $staff_name . '</a>'; } // Testimonials Tax if (is_tax('testimonials_category') && $testimonials_url) { $trail[] = '<a href="' . $testimonials_url . '" title="' . $testimonials_name . '">' . $testimonials_name . '</a>'; } /* Get the path to the term archive. Use this to determine if a page is present with it. */ if (is_category()) { $path = get_option('category_base'); } elseif (is_tag()) { $path = get_option('tag_base'); } else { if ($taxonomy->rewrite['with_front'] && $wp_rewrite->front) { $path = trailingslashit($wp_rewrite->front); } $path .= $taxonomy->rewrite['slug']; } /* Get parent pages by path if they exist. */ if ($path) { $trail = array_merge($trail, wpex_breadcrumbs_get_parents('', $path)); } /* If the taxonomy is hierarchical, list its parent terms. */ if (is_taxonomy_hierarchical($term->taxonomy) && $term->parent) { $trail = array_merge($trail, wpex_breadcrumbs_get_term_parents($term->parent, $term->taxonomy)); } /* Add the term name to the trail end. */ $trail['trail_end'] = $term->name; } elseif (function_exists('is_post_type_archive') && is_post_type_archive()) { /* Get the post type object. */ $post_type_object = get_post_type_object(get_query_var('post_type')); /* If $front has been set, add it to the $path. */ if ($post_type_object->rewrite['with_front'] && $wp_rewrite->front) { $path .= trailingslashit($wp_rewrite->front); } /* If there's a slug, add it to the $path. */ if (!empty($post_type_object->rewrite['archive'])) { $path .= $post_type_object->rewrite['archive']; } /* If there's a path, check for parents. */ if (!empty($path)) { $trail = array_merge($trail, wpex_breadcrumbs_get_parents('', $path)); } /* Add the post type [plural] name to the trail end. */ $trail['trail_end'] = $post_type_object->labels->name; } elseif (is_author()) { /* If $front has been set, add it to $path. */ if (!empty($wp_rewrite->front)) { $path .= trailingslashit($wp_rewrite->front); } /* If an $author_base exists, add it to $path. */ if (!empty($wp_rewrite->author_base)) { $path .= $wp_rewrite->author_base; } /* If $path exists, check for parent pages. */ if (!empty($path)) { $trail = array_merge($trail, wpex_breadcrumbs_get_parents('', $path)); } /* Add the author's display name to the trail end. */ $trail['trail_end'] = get_the_author_meta('display_name', get_query_var('author')); } elseif (is_time()) { if (get_query_var('minute') && get_query_var('hour')) { $trail['trail_end'] = get_the_time(__('g:i a', 'wpex')); } elseif (get_query_var('minute')) { $trail['trail_end'] = sprintf(__('Minute %1$s', 'wpex'), get_the_time(__('i', 'wpex'))); } elseif (get_query_var('hour')) { $trail['trail_end'] = get_the_time(__('g a', 'wpex')); } } elseif (is_date()) { /* If $front has been set, check for parent pages. */ if ($wp_rewrite->front) { $trail = array_merge($trail, wpex_breadcrumbs_get_parents('', $wp_rewrite->front)); } if (is_day()) { $trail[] = '<a href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time(esc_attr__('Y', 'wpex')) . '">' . get_the_time(__('Y', 'wpex')) . '</a>'; $trail[] = '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '" title="' . get_the_time(esc_attr__('F', 'wpex')) . '">' . get_the_time(__('F', 'wpex')) . '</a>'; $trail['trail_end'] = get_the_time(__('j', 'wpex')); } elseif (get_query_var('w')) { $trail[] = '<a href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time(esc_attr__('Y', 'wpex')) . '">' . get_the_time(__('Y', 'wpex')) . '</a>'; $trail['trail_end'] = sprintf(__('Week %1$s', 'wpex'), get_the_time(esc_attr__('W', 'wpex'))); } elseif (is_month()) { $trail[] = '<a href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time(esc_attr__('Y', 'wpex')) . '">' . get_the_time(__('Y', 'wpex')) . '</a>'; $trail['trail_end'] = get_the_time(__('F', 'wpex')); } elseif (is_year()) { $trail['trail_end'] = get_the_time(__('Y', 'wpex')); } } } elseif (is_search()) { $trail['trail_end'] = sprintf(__('Search results for "%1$s"', 'wpex'), esc_attr(get_search_query())); } elseif (is_404()) { $trail['trail_end'] = __('404 Not Found', 'wpex'); } /* Allow child themes/plugins to filter the trail array. */ $trail = apply_filters('wpex_breadcrumbs_trail', $trail, $args); /* Connect the breadcrumb trail if there are items in the trail. */ if (is_array($trail)) { /* Open the breadcrumb trail containers. */ $breadcrumb = '<nav class="site-breadcrumbs clr"><div class="breadcrumb-trail">'; /* If $before was set, wrap it in a container. */ if (!empty($before)) { $breadcrumb .= '<span class="trail-before">' . $before . '</span> '; } /* Wrap the $trail['trail_end'] value in a container. */ if (!empty($trail['trail_end'])) { $trail['trail_end'] = '<span class="trail-end">' . $trail['trail_end'] . '</span>'; } /* Format the separator. */ if (!empty($separator)) { $separator = '<span class="sep">' . $separator . '</span>'; } /* Join the individual trail items into a single string. */ $breadcrumb .= join(" {$separator} ", $trail); /* If $after was set, wrap it in a container. */ if (!empty($after)) { $breadcrumb .= ' <span class="trail-after">' . $after . '</span>'; } /* Close the breadcrumb trail containers. */ $breadcrumb .= '</div></nav>'; } /* Allow developers to filter the breadcrumb trail HTML. */ $breadcrumb = apply_filters('wpex_breadcrumbs', $breadcrumb); /* Output the breadcrumb. */ if ($echo) { echo $breadcrumb; } else { return $breadcrumb; } }