コード例 #1
0
function yoast_breadcrumb($prefix = '', $suffix = '', $display = true)
{
    global $wp_query, $post;
    $opt = get_option("yoast_breadcrumbs");
    if (!function_exists('bold_or_not')) {
        function bold_or_not($input)
        {
            $opt = get_option("yoast_breadcrumbs");
            if ($opt['boldlast']) {
                return '<strong>' . $input . '</strong>';
            } else {
                return $input;
            }
        }
    }
    if (!function_exists('yoast_get_category_parents')) {
        // Copied and adapted from WP source
        function yoast_get_category_parents($id, $link = FALSE, $separator = '/', $nicename = FALSE)
        {
            $chain = '';
            $parent =& get_category($id);
            if (is_wp_error($parent)) {
                return $parent;
            }
            if ($nicename) {
                $name = $parent->slug;
            } else {
                $name = $parent->cat_name;
            }
            if ($parent->parent && $parent->parent != $parent->term_id) {
                $chain .= get_category_parents($parent->parent, true, $separator, $nicename);
            }
            $chain .= bold_or_not($name);
            return $chain;
        }
    }
    $nofollow = ' ';
    if ($opt['nofollowhome']) {
        $nofollow = ' rel="nofollow" ';
    }
    $on_front = get_option('show_on_front');
    if ($on_front == "page") {
        $homelink = '<a' . $nofollow . 'href="' . get_permalink(get_option('page_on_front')) . '">' . $opt['home'] . '</a>';
        $bloglink = $homelink . ' ' . $opt['sep'] . ' <a href="' . get_permalink(get_option('page_for_posts')) . '">' . $opt['blog'] . '</a>';
    } else {
        $homelink = '<a' . $nofollow . 'href="' . get_bloginfo('url') . '">' . $opt['home'] . '</a>';
        $bloglink = $homelink;
    }
    if ($on_front == "page" && is_front_page() || $on_front == "posts" && is_home()) {
        $output = bold_or_not($opt['home']);
    } elseif ($on_front == "page" && is_home()) {
        $output = $homelink . ' ' . $opt['sep'] . ' ' . bold_or_not($opt['blog']);
    } elseif (!is_page()) {
        $output = $bloglink . ' ' . $opt['sep'] . ' ';
        if ((is_single() || is_category() || is_tag() || is_date() || is_author()) && $opt['singleparent'] != false) {
            $output .= '<a href="' . get_permalink($opt['singleparent']) . '">' . get_the_title($opt['singleparent']) . '</a> ' . $opt['sep'] . ' ';
        }
        if (is_single() && $opt['singlecatprefix']) {
            $cats = get_the_category();
            $cat = $cats[0];
            if (is_object($cat)) {
                if ($cat->parent != 0) {
                    $output .= get_category_parents($cat->term_id, true, " " . $opt['sep'] . " ");
                } else {
                    $output .= '<a href="' . get_category_link($cat->term_id) . '">' . $cat->name . '</a> ' . $opt['sep'] . ' ';
                }
            }
        }
        if (is_category()) {
            $cat = intval(get_query_var('cat'));
            $output .= yoast_get_category_parents($cat, false, " " . $opt['sep'] . " ");
        } elseif (is_tag()) {
            $output .= bold_or_not($opt['archiveprefix'] . " " . single_cat_title('', false));
        } elseif (is_date()) {
            $output .= bold_or_not($opt['archiveprefix'] . " " . single_month_title(' ', false));
        } elseif (is_author()) {
            $user = get_userdatabylogin($wp_query->query_vars['author_name']);
            $output .= bold_or_not($opt['archiveprefix'] . " " . $user->display_name);
        } elseif (is_search()) {
            $output .= bold_or_not($opt['searchprefix'] . ' "' . stripslashes(strip_tags(get_search_query())) . '"');
        } else {
            if (is_tax()) {
                $taxonomy = get_taxonomy(get_query_var('taxonomy'));
                $term = get_query_var('term');
                $output .= $taxonomy->label . ': ' . bold_or_not($term);
            } else {
                $output .= bold_or_not(get_the_title());
            }
        }
    } else {
        $post = $wp_query->get_queried_object();
        // If this is a top level Page, it's simple to output the breadcrumb
        if (0 == $post->post_parent) {
            $output = $homelink . " " . $opt['sep'] . " " . bold_or_not(get_the_title());
        } else {
            if (isset($post->ancestors)) {
                if (is_array($post->ancestors)) {
                    $ancestors = array_values($post->ancestors);
                } else {
                    $ancestors = array($post->ancestors);
                }
            } else {
                $ancestors = array($post->post_parent);
            }
            // Reverse the order so it's oldest to newest
            $ancestors = array_reverse($ancestors);
            // Add the current Page to the ancestors list (as we need it's title too)
            $ancestors[] = $post->ID;
            $links = array();
            foreach ($ancestors as $ancestor) {
                $tmp = array();
                $tmp['title'] = strip_tags(get_the_title($ancestor));
                $tmp['url'] = get_permalink($ancestor);
                $tmp['cur'] = false;
                if ($ancestor == $post->ID) {
                    $tmp['cur'] = true;
                }
                $links[] = $tmp;
            }
            $output = $homelink;
            foreach ($links as $link) {
                $output .= ' ' . $opt['sep'] . ' ';
                if (!$link['cur']) {
                    $output .= '<a href="' . $link['url'] . '">' . $link['title'] . '</a>';
                } else {
                    $output .= bold_or_not($link['title']);
                }
            }
        }
    }
    if ($opt['prefix'] != "") {
        $output = $opt['prefix'] . " " . $output;
    }
    if ($display) {
        echo $prefix . $output . $suffix;
    } else {
        return $prefix . $output . $suffix;
    }
}
コード例 #2
0
function yoast_breadcrumb($prefix = '', $suffix = '', $display = true)
{
    global $wp_query, $post, $curauth;
    $opt = get_option("yoast_breadcrumbs");
    function bold_or_not($input)
    {
        $opt = get_option("yoast_breadcrumbs");
        if ($opt['boldlast']) {
            return '' . $input . '';
        } else {
            return $input;
        }
    }
    // Copied and adapted from WP source
    function yoast_get_category_parents($id, $link = FALSE, $separator = '/', $nicename = FALSE)
    {
        $chain = '';
        $parent =& get_category($id);
        if (is_wp_error($parent)) {
            return $parent;
        }
        if ($nicename) {
            $name = $parent->slug;
        } else {
            $name = $parent->cat_name;
        }
        if ($parent->parent && $parent->parent != $parent->term_id) {
            $chain .= get_category_parents($parent->parent, true, $separator, $nicename);
        }
        $chain .= bold_or_not($name);
        return $chain;
    }
    function yoast_get_term_parents($id, $term_type = 'category', $link = FALSE, $separator = '/', $nicename = FALSE)
    {
        $chain = '';
        $category = get_term($id, $term_type, $output, $filter);
        if (is_wp_error($category)) {
            return $category;
        }
        _make_cat_compat($category);
        $parent = $category;
        if (is_wp_error($parent)) {
            return $parent;
        }
        if ($nicename) {
            $name = $parent->slug;
        } else {
            $name = $parent->cat_name;
        }
        $term_child = get_term_children($id, $term_type);
        if ($parent->parent && $parent->parent != $parent->term_id) {
            $chain .= '<a href="' . get_term_link($parent->parent, $term_type) . '">' . yoast_get_term_parents($parent->parent, $term_type, true, $separator, $nicename) . '</a>' . $separator;
        }
        $chain .= bold_or_not($name);
        return $chain;
    }
    $nofollow = ' ';
    if ($opt['nofollowhome']) {
        $nofollow = ' rel="nofollow" ';
    }
    $on_front = get_option('show_on_front');
    if ($on_front == "page") {
        $homelink = '<a' . $nofollow . 'href="' . get_permalink(get_option('page_on_front')) . '">' . $opt['home'] . '</a>';
        $bloglink = $homelink . ' ' . $opt['sep'] . ' <a href="' . get_permalink(get_option('page_for_posts')) . '">' . $opt['blog'] . '</a>';
    } else {
        $homelink = '<a' . $nofollow . 'href="' . get_bloginfo('url') . '">' . $opt['home'] . '</a>';
        $bloglink = $homelink;
    }
    if ($on_front == "page" && is_front_page() || $on_front == "posts" && is_home()) {
        $output = bold_or_not($opt['home']);
    } elseif ($on_front == "page" && is_home()) {
        $output = $homelink . ' ' . $opt['sep'] . ' ' . bold_or_not($opt['blog']);
    } elseif (!is_page()) {
        $output = $bloglink . ' ' . $opt['sep'] . ' ';
        if ((is_single() || is_category() || is_tag() || is_date() || is_author()) && $opt['singleparent'] != 0) {
            $output .= '<a href="' . get_permalink($opt['singleparent']) . '">' . get_the_title($opt['singleparent']) . '</a> ' . $opt['sep'] . ' ';
        }
        if (is_single() && $opt['singlecatprefix']) {
            if ($post->post_type == CUSTOM_POST_TYPE1) {
                global $post;
                $cats = wp_get_post_terms($post->ID, CUSTOM_CATEGORY_TYPE1);
                $cat = $cats[0];
                //$output .= yoast_get_term_parents($cat->term_id,CUSTOM_CATEGORY_TYPE1, true, " ".$opt['sep']." ");
                $output .= join(" " . $opt['sep'] . " ", get_the_taxonomies($post)) . " " . $opt['sep'] . " ";
            } else {
                $cats = get_the_category();
                $cat = $cats[0];
                if ($cat) {
                    $output .= get_category_parents($cat->term_id, true, " " . $opt['sep'] . " ");
                }
            }
        }
        if (is_archive()) {
            if (is_tag()) {
                $output .= bold_or_not($opt['archiveprefix'] . " " . single_cat_title('', false));
            } elseif (is_date()) {
                $output .= bold_or_not($opt['archiveprefix'] . " " . single_month_title(' ', false));
            } elseif (is_author()) {
                $user = get_userdatabylogin($wp_query->query_vars['author_name']);
                $output .= bold_or_not($opt['archiveprefix'] . " " . $curauth->nickname);
            } elseif (is_category()) {
                $cat = intval(get_query_var('cat'));
                $output .= yoast_get_category_parents($cat, false, " " . $opt['sep'] . " ");
            } elseif (is_year()) {
                $output .= bold_or_not($opt['archiveprefix'] . " " . get_the_time('Y'));
            } elseif (is_month()) {
                $output .= bold_or_not($opt['archiveprefix'] . " " . get_the_time('F, Y'));
            } elseif (is_date()) {
                $output .= bold_or_not($opt['archiveprefix'] . " " . get_the_time('F jS, Y'));
            } else {
                global $wp_query, $post;
                $cat = $wp_query->get_queried_object();
                $output .= yoast_get_term_parents($cat, $term_type = CUSTOM_CATEGORY_TYPE1, false, " " . $opt['sep'] . " ");
            }
        } elseif (is_search()) {
            $output .= bold_or_not(get_search_query());
        } else {
            $output .= bold_or_not(get_the_title());
        }
    } else {
        $post = $wp_query->get_queried_object();
        // If this is a top level Page, it's simple to output the breadcrumb
        if (0 == $post->post_parent) {
            $output = $homelink . " " . $opt['sep'] . " " . bold_or_not(get_the_title());
        } else {
            if (isset($post->ancestors)) {
                if (is_array($post->ancestors)) {
                    $ancestors = array_values($post->ancestors);
                } else {
                    $ancestors = array($post->ancestors);
                }
            } else {
                $ancestors = array($post->post_parent);
            }
            // Reverse the order so it's oldest to newest
            $ancestors = array_reverse($ancestors);
            // Add the current Page to the ancestors list (as we need it's title too)
            $ancestors[] = $post->ID;
            $links = array();
            foreach ($ancestors as $ancestor) {
                $tmp = array();
                $tmp['title'] = strip_tags(get_the_title($ancestor));
                $tmp['url'] = get_permalink($ancestor);
                $tmp['cur'] = false;
                if ($ancestor == $post->ID) {
                    $tmp['cur'] = true;
                }
                $links[] = $tmp;
            }
            $output = $homelink;
            foreach ($links as $link) {
                $output .= ' ' . $opt['sep'] . ' ';
                if (!$link['cur']) {
                    $output .= '<a href="' . $link['url'] . '">' . $link['title'] . '</a>';
                } else {
                    $output .= bold_or_not($link['title']);
                }
            }
        }
    }
    if ($opt['prefix'] != "") {
        $output = $opt['prefix'] . " " . $output;
    }
    if ($display) {
        echo $prefix . $output . $suffix;
    } else {
        return $prefix . $output . $suffix;
    }
}
コード例 #3
0
 function yoast_breadcrumb_cb($prefix = '<div class="breadcrumbs">', $suffix = '</div><div class="clear"></div>', $display = true)
 {
     global $wpdb, $wp_query, $post, $query_string;
     // Load some defaults
     $br_opt = array();
     $br_opt['home'] = __('Home', 'wip');
     $br_opt['blog'] = __('Blog', 'wip');
     $br_opt['sep'] = '<span class="bread-divider">></span>';
     $br_opt['prefix'] = __('', 'wip');
     $br_opt['boldlast'] = true;
     $br_opt['nofollowhome'] = false;
     $br_opt['singleparent'] = 0;
     $br_opt['singlecatprefix'] = true;
     $br_opt['archiveprefix'] = __('Archives for', 'wip');
     $br_opt['searchprefix'] = __('Search results for', 'wip');
     if (!function_exists('yoast_get_category_parents')) {
         // Copied and adapted from WP source
         function yoast_get_category_parents($id, $link = FALSE, $separator = '/', $nicename = FALSE)
         {
             $chain = '';
             $parent =& get_category($id);
             if (is_wp_error($parent)) {
                 return $parent;
             }
             if ($nicename) {
                 $name = $parent->slug;
             } else {
                 $name = $parent->name;
             }
             if ($parent->parent && $parent->parent != $parent->term_id) {
                 $chain .= get_category_parents($parent->parent, true, $separator, $nicename);
             }
             $chain .= bold_take_not($name);
             return $chain;
         }
     }
     function WIPTakeTaxonomyParent($id, $taxName = 'category', $separator)
     {
         if ($id == '') {
             $id = 0;
         }
         if (!is_object($id)) {
             $id = (int) $id;
         }
         if ($taxName == '') {
             return $id;
         }
         $parents = get_term_by('id', $id, $taxName);
         $parent = '';
         if ($parents->parent && $parents->parent != $id) {
             $par = get_term_by('id', $parents->parent, $taxName);
             if (WIPTakeTaxonomyParent($par->term_id, $taxName, '')) {
                 $parent = WIPTakeTaxonomyParent($par->term_id, $taxName, $separator);
             }
             $parent .= '<a href="' . get_term_link((int) $parents->parent, $taxName) . '">' . $par->name . '</a> ';
             if ($separator) {
                 $parent .= $separator;
             }
             return $parent;
         }
         return false;
     }
     $prepend = '';
     if (woocommerce_found() && (get_option('woocommerce_prepend_shop_page_to_urls') == "yes" && woocommerce_get_page_id('shop') && get_option('page_on_front') !== woocommerce_get_page_id('shop'))) {
         $prepend = '<a href="' . get_permalink(woocommerce_get_page_id('shop')) . '">' . get_the_title(woocommerce_get_page_id('shop')) . '</a> ' . $br_opt['sep'];
     }
     $nofollow = ' ';
     if ($br_opt['nofollowhome']) {
         $nofollow = ' rel="nofollow" ';
     }
     $on_front = get_option('show_on_front');
     if ($on_front == "page") {
         $homelink = '<a' . $nofollow . 'href="' . get_permalink(get_option('page_on_front')) . '" class="breadcrumb_home">' . $br_opt['home'] . '</a>';
         $bloglink = $homelink . $br_opt['sep'] . ' <a href="' . get_permalink(get_option('page_for_posts')) . '">' . $br_opt['blog'] . '</a>';
     } else {
         $homelink = '<a' . $nofollow . 'href="' . home_url() . '" class="breadcrumb_home" title="' . __('Homepage', 'wip') . '">' . $br_opt['home'] . '</a>';
         $bloglink = $homelink;
     }
     if ($on_front == "page" && is_front_page() || $on_front == "posts" && is_home()) {
         $output = bold_take_not($br_opt['home']);
     } elseif ($on_front == "page" && is_home()) {
         $output = $homelink . $br_opt['sep'] . bold_take_not($br_opt['blog']);
     } elseif (!is_page()) {
         $output = $bloglink . $br_opt['sep'];
         if ((is_single() || is_category() || is_tag() || is_date() || is_author()) && $br_opt['singleparent'] != false) {
             $output .= '<a href="' . get_permalink($br_opt['singleparent']) . '">' . get_the_title($br_opt['singleparent']) . '</a> ' . $br_opt['sep'];
         }
         if (is_single() && $br_opt['singlecatprefix']) {
             $p_type = get_post_type();
             if ($p_type == "post") {
                 $cats = get_the_category();
                 $cat = $cats[0];
                 if (is_object($cat)) {
                     if (WIPTakeTaxonomyParent($cat->term_id, 'category', '')) {
                         $output .= WIPTakeTaxonomyParent($cat->term_id, 'category', $br_opt['sep']);
                     }
                     $output .= '<a href="' . get_category_link($cat->term_id) . '">' . $cat->name . '</a>' . $br_opt['sep'];
                 }
             } else {
                 if ($p_type == "product") {
                     $output .= $prepend;
                     $trm = wp_get_object_terms($post->ID, 'product_cat');
                     $trms = $trm[0];
                     $tera = get_term_by('id', $trms->term_id, 'product_cat');
                     $tera_link = get_term_link((int) $trms->term_id, 'product_cat');
                     if ($trm) {
                         if (WIPTakeTaxonomyParent($tera->term_id, 'product_cat', '')) {
                             $output .= WIPTakeTaxonomyParent($tera->term_id, 'product_cat', $br_opt['sep']);
                         }
                         $output .= '<a href="' . $tera_link . '">' . $tera->name . '</a>';
                         $output .= $br_opt['sep'];
                     }
                 } else {
                     if ($p_type == "portfolio-item") {
                         $trm = wp_get_object_terms($post->ID, 'portfolio-category');
                         $trms = $trm[0];
                         $tera = get_term_by('id', $trms->term_id, 'portfolio-category');
                         $tera_link = get_term_link((int) $trms->term_id, 'portfolio-category');
                         if ($trm) {
                             if (WIPTakeTaxonomyParent($tera->term_id, 'portfolio-category', '')) {
                                 $output .= WIPTakeTaxonomyParent($tera->term_id, 'portfolio-category', $br_opt['sep']);
                             }
                             $output .= '<a href="' . $tera_link . '">' . $tera->name . '</a>';
                             $output .= $br_opt['sep'];
                         }
                     }
                 }
             }
         } elseif (woocommerce_found() && (is_post_type_archive('product') && get_option('page_on_front') !== woocommerce_get_page_id('shop'))) {
             $_name = woocommerce_get_page_id('shop') ? get_the_title(woocommerce_get_page_id('shop')) : ucwords(get_option('woocommerce_shop_slug'));
             if (is_search()) {
                 $output .= '<a href="' . get_post_type_archive_link('product') . '">' . $_name . '</a>' . $br_opt['sep'];
                 $output .= bold_take_not(sprintf(__('Search results for &ldquo;%s&ldquo;', 'woocommerce'), get_search_query()));
             } else {
                 $output .= bold_take_not($_name);
             }
         }
         if (is_category()) {
             $cat = intval(get_query_var('cat'));
             $output .= yoast_get_category_parents($cat, false, $br_opt['sep']);
         } elseif (is_tag()) {
             $output .= bold_take_not($br_opt['archiveprefix'] . single_cat_title('', false));
         } elseif (is_date()) {
             $output .= bold_take_not($br_opt['archiveprefix'] . single_month_title(' ', false));
         } elseif (is_author()) {
             $user = wp_title("", false);
             $output .= bold_take_not($br_opt['archiveprefix'] . $user);
         } elseif (is_search()) {
             if (!is_post_type_archive('product')) {
                 $output .= bold_take_not($br_opt['searchprefix'] . '"' . stripslashes(strip_tags(get_search_query())) . '"');
             }
         } else {
             if (is_tax('product_cat')) {
                 $output .= $prepend;
                 $termos = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
                 if (WIPTakeTaxonomyParent($termos->term_id, 'product_cat', '')) {
                     $output .= WIPTakeTaxonomyParent($termos->term_id, 'product_cat', $br_opt['sep']);
                 }
                 $output .= bold_take_not($termos->name);
             } else {
                 if (is_tax('product_tag')) {
                     $output .= $prepend;
                     $queried_object = $wp_query->get_queried_object();
                     $output .= bold_take_not($queried_object->name);
                 } else {
                     if (is_tax('portfolio-category')) {
                         $termos = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
                         if (WIPTakeTaxonomyParent($termos->term_id, 'portfolio-category', '')) {
                             $output .= WIPTakeTaxonomyParent($termos->term_id, 'portfolio-category', $br_opt['sep']);
                         }
                         $output .= bold_take_not($termos->name);
                     } else {
                         if (!is_post_type_archive('product')) {
                             $output .= bold_take_not(get_the_title());
                         }
                     }
                 }
             }
         }
     } else {
         $post = $wp_query->get_queried_object();
         if ($post->post_type == 'page') {
             // If this is a top level Page, it's simple to output the breadcrumb
             if (0 == $post->post_parent) {
                 $output = $homelink . $br_opt['sep'] . bold_take_not(get_the_title());
             } else {
                 if (isset($post->ancestors)) {
                     if (is_array($post->ancestors)) {
                         $ancestors = array_values($post->ancestors);
                     } else {
                         $ancestors = array($post->ancestors);
                     }
                 } else {
                     $ancestors = array($post->post_parent);
                 }
                 // Reverse the order so it's oldest to newest
                 $ancestors = array_reverse($ancestors);
                 // Add the current Page to the ancestors list (as we need it's title too)
                 $ancestors[] = $post->ID;
                 $links = array();
                 foreach ($ancestors as $ancestor) {
                     $tmp = array();
                     $tmp['title'] = strip_tags(get_the_title($ancestor));
                     $tmp['url'] = get_permalink($ancestor);
                     $tmp['cur'] = false;
                     if ($ancestor == $post->ID) {
                         $tmp['cur'] = true;
                     }
                     $links[] = $tmp;
                 }
                 $output = $homelink;
                 foreach ($links as $link) {
                     $output .= ' ' . $br_opt['sep'] . ' ';
                     if (!$link['cur']) {
                         $output .= '<a href="' . $link['url'] . '">' . $link['title'] . '</a>';
                     } else {
                         $output .= bold_take_not($link['title']);
                     }
                 }
             }
         }
     }
     if ($br_opt['prefix'] != "") {
         $output = $br_opt['prefix'] . " " . $output;
     }
     if ($display) {
         echo $prefix . $output . $suffix;
     } else {
         return $prefix . $output . $suffix;
     }
 }