function avia_modify_breadcrumb($trail)
 {
     $parent = get_post_meta(avia_get_the_ID(), 'breadcrumb_parent', true);
     if (get_post_type() === "portfolio") {
         $page = "";
         $front = avia_get_option('frontpage');
         if (empty($parent) && !current_theme_supports('avia_no_session_support') && session_id() && !empty($_SESSION['avia_portfolio'])) {
             $page = $_SESSION['avia_portfolio'];
         } else {
             $page = $parent;
         }
         if (!$page || $page == $front) {
             $args = array('post_type' => 'page', 'meta_query' => array(array('key' => '_avia_builder_shortcode_tree', 'value' => 'av_portfolio', 'compare' => 'LIKE')));
             $query = new WP_Query($args);
             if ($query->post_count == 1) {
                 $page = $query->posts[0]->ID;
             } else {
                 if ($query->post_count > 1) {
                     foreach ($query->posts as $entry) {
                         if ($front != $entry->ID) {
                             $page = $entry->ID;
                             break;
                         }
                     }
                 }
             }
         }
         if ($page) {
             if ($page == $front) {
                 $newtrail[0] = $trail[0];
                 $newtrail['trail_end'] = $trail['trail_end'];
                 $trail = $newtrail;
             } else {
                 $newtrail = avia_breadcrumbs_get_parents($page, '');
                 array_unshift($newtrail, $trail[0]);
                 $newtrail['trail_end'] = $trail['trail_end'];
                 $trail = $newtrail;
             }
         }
     } else {
         if (get_post_type() === "post" && (is_category() || is_archive() || is_tag())) {
             $front = avia_get_option('frontpage');
             $blog = !empty($parent) ? $parent : avia_get_option('blogpage');
             if ($front && $blog && $front != $blog) {
                 $blog = '<a href="' . get_permalink($blog) . '" title="' . esc_attr(get_the_title($blog)) . '">' . get_the_title($blog) . '</a>';
                 array_splice($trail, 1, 0, array($blog));
             }
         } else {
             if (get_post_type() === "post") {
                 $front = avia_get_option('frontpage');
                 $blog = avia_get_option('blogpage');
                 $custom_blog = avia_get_option('blog_style') === 'custom' ? true : false;
                 if (!$custom_blog) {
                     if ($blog == $front) {
                         unset($trail[1]);
                     }
                 } else {
                     if ($blog != $front) {
                         $blog = '<a href="' . get_permalink($blog) . '" title="' . esc_attr(get_the_title($blog)) . '">' . get_the_title($blog) . '</a>';
                         array_splice($trail, 1, 0, array($blog));
                     }
                 }
             }
         }
     }
     return $trail;
 }
Esempio n. 2
0
 function avia_woocommerce_breadcrumb($trail)
 {
     global $avia_config;
     if (is_woocommerce()) {
         $home = $trail[0];
         $last = array_pop($trail);
         $shop_id = woocommerce_get_page_id('shop');
         $taxonomy = "product_cat";
         // on the shop frontpage simply display the shop name, rather than shop name + "All Products"
         if (is_shop()) {
             if (!empty($shop_id) && $shop_id != -1) {
                 $trail = array_merge($trail, avia_breadcrumbs_get_parents($shop_id));
             }
             $last = "";
             if (is_search()) {
                 $last = __('Search results for:', 'avia_framework') . ' ' . esc_attr($_GET['s']);
             }
         }
         // on the product page single page modify the breadcrumb to read [home] [if available:parent shop pages] [shop] [if available:parent categories] [category] [title]
         if (is_product()) {
             //fetch all product categories and search for the ones with parents. if none are avalaible use the first category found
             $product_category = $parent_cat = array();
             $temp_cats = get_the_terms(get_the_ID(), $taxonomy);
             if (!empty($temp_cats)) {
                 foreach ($temp_cats as $key => $cat) {
                     if ($cat->parent != 0 && !in_array($cat->term_taxonomy_id, $parent_cat)) {
                         $product_category[] = $cat;
                         $parent_cat[] = $cat->parent;
                     }
                 }
                 //if no categories with parents use the first one
                 if (empty($product_category)) {
                     $product_category[] = reset($temp_cats);
                 }
             }
             //unset the trail and build our own
             unset($trail);
             $trail[0] = $home;
             if (!empty($shop_id) && $shop_id != -1) {
                 $trail = array_merge($trail, avia_breadcrumbs_get_parents($shop_id));
             }
             if (!empty($parent_cat)) {
                 $trail = array_merge($trail, avia_breadcrumbs_get_term_parents($parent_cat[0], $taxonomy));
             }
             if (!empty($product_category)) {
                 $trail[] = '<a href="' . get_term_link($product_category[0]->slug, $taxonomy) . '" title="' . esc_attr($product_category[0]->name) . '">' . $product_category[0]->name . '</a>';
             }
         }
         // add the [shop] trail to category/tag pages: [home] [if available:parent shop pages] [shop] [if available:parent categories] [category/tag]
         if (is_product_category() || is_product_tag()) {
             if (!empty($shop_id) && $shop_id != -1) {
                 $shop_trail = avia_breadcrumbs_get_parents($shop_id);
                 array_splice($trail, 1, 0, $shop_trail);
             }
         }
         if (is_product_tag()) {
             $last = __("Tag", 'avia_framework') . ": " . $last;
         }
         if (!empty($last)) {
             $trail[] = $last;
         }
     }
     return $trail;
 }
Esempio n. 3
0
/**
 * The code below is an inspired/modified version by woothemes breadcrumb function which in turn is inspired by Justin Tadlock's Hybrid Core :)
 */
function avia_breadcrumbs($args = array())
{
    global $wp_query, $wp_rewrite;
    /* 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' => '&raquo;', 'before' => '<span class="breadcrumb-title">' . __('You are here:', 'avia_framework') . '</span>', 'after' => false, 'front_page' => true, 'show_home' => __('Home', 'avia_framework'), 'echo' => false, 'show_categories' => true, 'show_posts_page' => true, 'truncate' => 70, 'richsnippet' => false);
    /* 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('avia_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, avia_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, avia_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')) {
                $trail[] = '<a href="' . get_post_type_archive_link($post_type) . '" title="' . esc_attr($post_type_object->labels->name) . '">' . $post_type_object->labels->name . '</a>';
            }
        }
        /* try to build a generic taxonomy trail no matter the post type and taxonomy and terms
        		$currentTax = "";
        		foreach(get_taxonomies() as $tax)
        		{
        			$terms = get_the_term_list( $post_id, $tax, '', '$$$', '' );
        			echo"<pre>";
        			print_r($tax.$terms);
        			echo"</pre>";
        		}
        		*/
        /* 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, avia_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, avia_breadcrumbs_get_parents($posts_page, ''));
            }
        }
        if ('post' == $post_type && $show_categories) {
            $category = get_the_category();
            foreach ($category as $cat) {
                if (!empty($cat->parent)) {
                    $parents = get_category_parents($cat->cat_ID, TRUE, '$$$', FALSE);
                    $parents = explode("\$\$\$", $parents);
                    foreach ($parents as $parent_item) {
                        if ($parent_item) {
                            $trail[] = $parent_item;
                        }
                    }
                    break;
                }
            }
            if (isset($category[0]) && empty($parents)) {
                $trail[] = '<a href="' . get_category_link($category[0]->term_id) . '">' . $category[0]->cat_name . '</a>';
            }
        }
        if ($post_type == 'portfolio') {
            $parents = get_the_term_list($post_id, 'portfolio_entries', '', '$$$', '');
            $parents = explode('$$$', $parents);
            foreach ($parents as $parent_item) {
                if ($parent_item) {
                    $trail[] = $parent_item;
                }
            }
        }
        /* 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)) {
            $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);
            /* 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, avia_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, avia_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, avia_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, avia_breadcrumbs_get_parents('', $path));
            }
            /* Add the author's display name to the trail end. */
            $trail['trail_end'] = apply_filters('avf_author_name', get_the_author_meta('display_name', get_query_var('author')), 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', 'avia_framework'));
            } elseif (get_query_var('minute')) {
                $trail['trail_end'] = sprintf(__('Minute %1$s', 'avia_framework'), get_the_time(__('i', 'avia_framework')));
            } elseif (get_query_var('hour')) {
                $trail['trail_end'] = get_the_time(__('g a', 'avia_framework'));
            }
        } elseif (is_date()) {
            /* If $front has been set, check for parent pages. */
            if ($wp_rewrite->front) {
                $trail = array_merge($trail, avia_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', 'avia_framework')) . '">' . get_the_time(__('Y', 'avia_framework')) . '</a>';
                $trail[] = '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '" title="' . get_the_time(esc_attr__('F', 'avia_framework')) . '">' . get_the_time(__('F', 'avia_framework')) . '</a>';
                $trail['trail_end'] = get_the_time(__('j', 'avia_framework'));
            } elseif (get_query_var('w')) {
                $trail[] = '<a href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time(esc_attr__('Y', 'avia_framework')) . '">' . get_the_time(__('Y', 'avia_framework')) . '</a>';
                $trail['trail_end'] = sprintf(__('Week %1$s', 'avia_framework'), get_the_time(esc_attr__('W', 'avia_framework')));
            } elseif (is_month()) {
                $trail[] = '<a href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time(esc_attr__('Y', 'avia_framework')) . '">' . get_the_time(__('Y', 'avia_framework')) . '</a>';
                $trail['trail_end'] = get_the_time(__('F', 'avia_framework'));
            } elseif (is_year()) {
                $trail['trail_end'] = get_the_time(__('Y', 'avia_framework'));
            }
        }
    } elseif (is_search()) {
        $trail['trail_end'] = sprintf(__('Search results for &quot;%1$s&quot;', 'avia_framework'), esc_attr(get_search_query()));
    } elseif (is_404()) {
        $trail['trail_end'] = __('404 Not Found', 'avia_framework');
    }
    /* Allow child themes/plugins to filter the trail array. */
    $trail = apply_filters('avia_breadcrumbs_trail', $trail, $args);
    /* Connect the breadcrumb trail if there are items in the trail. */
    if (is_array($trail)) {
        $el_tag = "span";
        $vocabulary = "";
        //google rich snippets
        if ($richsnippet === true) {
            $vocabulary = 'xmlns:v="http://rdf.data-vocabulary.org/#"';
        }
        /* Open the breadcrumb trail containers. */
        $breadcrumb = '<div class="breadcrumb breadcrumbs avia-breadcrumbs"><div class="breadcrumb-trail" ' . $vocabulary . '>';
        /* If $before was set, wrap it in a container. */
        if (!empty($before)) {
            $breadcrumb .= '<' . $el_tag . ' class="trail-before">' . $before . '</' . $el_tag . '> ';
        }
        /* Wrap the $trail['trail_end'] value in a container. */
        if (!empty($trail['trail_end'])) {
            if (!is_search()) {
                $trail['trail_end'] = avia_backend_truncate($trail['trail_end'], $truncate, " ", $pad = "...", false, '<strong><em><span>', true);
            }
            $trail['trail_end'] = '<' . $el_tag . ' class="trail-end">' . $trail['trail_end'] . '</' . $el_tag . '>';
        }
        if ($richsnippet === true) {
            foreach ($trail as $key => &$link) {
                if ("trail_end" == $key) {
                    continue;
                }
                $link = preg_replace('!rel=".+?"|rel=\'.+?\'|!', "", $link);
                $link = str_replace('<a ', '<a rel="v:url" property="v:title" ', $link);
                $link = '<span typeof="v:Breadcrumb">' . $link . '</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></div>';
    }
    /* Allow developers to filter the breadcrumb trail HTML. */
    $breadcrumb = apply_filters('avia_breadcrumbs', $breadcrumb);
    /* Output the breadcrumb. */
    if ($echo) {
        echo $breadcrumb;
    } else {
        return $breadcrumb;
    }
}