Ejemplo n.º 1
0
/**
 * Gets the items for the breadcrumbs plus.
 *
 * @since 0.4
 */
function breadcrumbs_plus_get_items($args)
{
    global $wp_query;
    $item = array();
    $show_on_front = get_option('show_on_front');
    /* Front page. */
    if (is_front_page()) {
        $item['last'] = $args['home'];
    }
    /* Link to front page. */
    if (!is_front_page()) {
        $item[] = '<div class="vbreadcrumb" typeof="v:Breadcrumb"><a href="' . home_url('/') . '" rel="v:url" property="v:title" class="home">' . $args['home'] . '</a></div>';
    }
    /* If bbPress is installed and we're on a bbPress page. */
    if (function_exists('is_bbpress') && is_bbpress()) {
        $item = array_merge($item, breadcrumbs_plus_get_bbpress_items());
    } elseif (is_home()) {
        $home_page = get_page($wp_query->get_queried_object_id());
        $item = array_merge($item, breadcrumbs_plus_get_parents($home_page->post_parent));
        $item['last'] = get_the_title($home_page->ID);
    } elseif (is_singular()) {
        $post = $wp_query->get_queried_object();
        $post_id = (int) $wp_query->get_queried_object_id();
        $post_type = $post->post_type;
        $post_type_object = get_post_type_object($post_type);
        if ('post' === $wp_query->post->post_type && $args['show_blog']) {
            $item[] = '<div class="vbreadcrumb" typeof="v:Breadcrumb"><a href="' . get_permalink(get_option('page_for_posts')) . '" rel="v:url" property="v:title">' . get_the_title(get_option('page_for_posts')) . '</a></div>';
        }
        if ('page' !== $wp_query->post->post_type) {
            /* If there's an archive page, add it. */
            if (function_exists('get_post_type_archive_link') && !empty($post_type_object->has_archive)) {
                $item[] = '<div class="vbreadcrumb" typeof="v:Breadcrumb"><a href="' . get_post_type_archive_link($post_type) . '" title="' . esc_attr($post_type_object->labels->name) . '" rel="v:url" property="v:title">' . $post_type_object->labels->name . '</a></div>';
            }
            if (isset($args["singular_{$wp_query->post->post_type}_taxonomy"]) && is_taxonomy_hierarchical($args["singular_{$wp_query->post->post_type}_taxonomy"])) {
                $terms = wp_get_object_terms($post_id, $args["singular_{$wp_query->post->post_type}_taxonomy"]);
                $item = array_merge($item, breadcrumbs_plus_get_term_parents($terms[0], $args["singular_{$wp_query->post->post_type}_taxonomy"]));
            } elseif (isset($args["singular_{$wp_query->post->post_type}_taxonomy"])) {
                $item[] = get_the_term_list($post_id, $args["singular_{$wp_query->post->post_type}_taxonomy"], '', ', ', '');
            }
        }
        if ((is_post_type_hierarchical($wp_query->post->post_type) || 'attachment' === $wp_query->post->post_type) && ($parents = breadcrumbs_plus_get_parents($wp_query->post->post_parent))) {
            $item = array_merge($item, $parents);
        }
        $item['last'] = '';
    } else {
        if (is_archive()) {
            if (is_category() || is_tag() || is_tax()) {
                $term = $wp_query->get_queried_object();
                $taxonomy = get_taxonomy($term->taxonomy);
                if (is_taxonomy_hierarchical($term->taxonomy) && $term->parent && ($parents = breadcrumbs_plus_get_term_parents($term->parent, $term->taxonomy))) {
                    $item = array_merge($item, $parents);
                }
                $item['last'] = $term->name;
            } else {
                if (function_exists('is_post_type_archive') && is_post_type_archive()) {
                    $post_type_object = get_post_type_object(get_query_var('post_type'));
                    $item['last'] = $post_type_object->labels->name;
                } else {
                    if (is_date()) {
                        if (is_day()) {
                            $item['last'] = __('Archives for ', 'framework') . get_the_time('F j, Y');
                        } elseif (is_month()) {
                            $item['last'] = __('Archives for ', 'framework') . single_month_title(' ', false);
                        } elseif (is_year()) {
                            $item['last'] = __('Archives for ', 'framework') . get_the_time('Y');
                        }
                    } else {
                        if (is_author()) {
                            $item['last'] = __('Archives by: ', 'framework') . get_the_author_meta('display_name', $wp_query->post->post_author);
                        }
                    }
                }
            }
        } else {
            if (is_search()) {
                $item['last'] = __('Search results for "', 'framework') . stripslashes(strip_tags(get_search_query())) . '"';
            } else {
                if (is_404()) {
                    $item['last'] = __('Page Not Found', 'framework');
                }
            }
        }
    }
    return apply_filters('breadcrumbs_plus_items', $item);
}
/**
 * Gets the items for the breadcrumbs plus.
 *
 * @since 0.4
 */
function breadcrumbs_plus_get_items($args)
{
    global $wp_query;
    $item = array();
    $show_on_front = get_option('show_on_front');
    /* Front page. */
    if (is_front_page()) {
        $item['last'] = $args['home'];
    }
    /* Link to front page. */
    if (!is_front_page()) {
        $item[] = '<a href="' . home_url('/') . '" class="home">' . $args['home'] . '</a>';
    }
    /* If bbPress is installed and we're on a bbPress page. */
    if (function_exists('is_bbpress') && is_bbpress()) {
        $item = array_merge($item, breadcrumbs_plus_get_bbpress_items());
    } elseif (is_home()) {
        $home_page = get_page($wp_query->get_queried_object_id());
        $item = array_merge($item, breadcrumbs_plus_get_parents($home_page->post_parent));
        $item['last'] = get_the_title($home_page->ID);
    } elseif (is_singular()) {
        $post = $wp_query->get_queried_object();
        $post_id = (int) $wp_query->get_queried_object_id();
        $post_type = $post->post_type;
        $post_type_object = get_post_type_object($post_type);
        if ('page' !== $wp_query->post->post_type) {
            /* If there's an archive page, add it. */
            if (function_exists('get_post_type_archive_link') && !empty($post_type_object->has_archive)) {
                $item[] = '<a href="' . get_post_type_archive_link($post_type) . '" title="' . esc_attr($post_type_object->labels->name) . '">' . $post_type_object->labels->name . '</a>';
            }
            if (isset($args["singular_{$wp_query->post->post_type}_taxonomy"]) && is_taxonomy_hierarchical($args["singular_{$wp_query->post->post_type}_taxonomy"])) {
                $terms = wp_get_object_terms($post_id, $args["singular_{$wp_query->post->post_type}_taxonomy"]);
                $item = array_merge($item, breadcrumbs_plus_get_term_parents($terms[0], $args["singular_{$wp_query->post->post_type}_taxonomy"]));
            } elseif (isset($args["singular_{$wp_query->post->post_type}_taxonomy"])) {
                $item[] = get_the_term_list($post_id, $args["singular_{$wp_query->post->post_type}_taxonomy"], '', ', ', '');
            }
        }
        if ((is_post_type_hierarchical($wp_query->post->post_type) || 'attachment' === $wp_query->post->post_type) && ($parents = breadcrumbs_plus_get_parents($wp_query->post->post_parent))) {
            $item = array_merge($item, $parents);
        }
        $item['last'] = get_the_title();
    } else {
        if (is_archive()) {
            if (is_category() || is_tag() || is_tax()) {
                $term = $wp_query->get_queried_object();
                $taxonomy = get_taxonomy($term->taxonomy);
                if (is_taxonomy_hierarchical($term->taxonomy) && $term->parent && ($parents = breadcrumbs_plus_get_term_parents($term->parent, $term->taxonomy))) {
                    $item = array_merge($item, $parents);
                }
                $item['last'] = $term->name;
            } else {
                if (function_exists('is_post_type_archive') && is_post_type_archive()) {
                    $post_type_object = get_post_type_object(get_query_var('post_type'));
                    $item['last'] = $post_type_object->labels->name;
                } else {
                    if (is_date()) {
                        if (is_numeric(get_query_var('w') && 0 !== get_query_var('w'))) {
                            $item['last'] = sprintf(__('Weekly Archive for: ‘%s’', 'theme_front'), get_the_time('W'));
                        } elseif (is_day()) {
                            $item['last'] = sprintf(__('Daily Archive for: ‘%s’', 'theme_front'), get_the_time('F jS, Y'));
                        } elseif (is_month()) {
                            $item['last'] = sprintf(__('Monthly Archive for: ‘%s’', 'theme_front'), get_the_time('F jS, Y'));
                        } elseif (is_year()) {
                            $item['last'] = sprintf(__('Yearly Archive for: ‘%s’', 'theme_front'), get_the_time('Y'));
                        }
                    } else {
                        if (is_author()) {
                            $item['last'] = sprintf(__('Author Archive for: ‘%s’', 'theme_front'), get_the_author_meta('display_name', $wp_query->post->post_author));
                        }
                    }
                }
            }
        } else {
            if (is_search()) {
                $item['last'] = sprintf(__('Search Results for: ‘%s’', 'theme_front'), stripslashes(strip_tags(get_search_query())));
            } else {
                if (is_404()) {
                    $item['last'] = __('Page Not Found', 'theme_front');
                }
            }
        }
    }
    return apply_filters('breadcrumbs_plus_items', $item);
}