Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function breadcrumb($prefix = '', $suffix = '', $display = true) {
- $options = get_wpseo_options();
- global $wp_query, $post, $paged;
- $opt = get_option("wpseo_internallinks");
- $on_front = get_option('show_on_front');
- $blog_page = get_option('page_for_posts');
- $sep = ( isset($opt['breadcrumbs-sep']) && $opt['breadcrumbs-sep'] != '' ) ? $opt['breadcrumbs-sep'] : '»';
- $hometitle = ( isset($opt['breadcrumbs-home']) && $opt['breadcrumbs-home'] != '' ) ? $opt['breadcrumbs-home'] : __('Home','wordpress-seo');
- // This doesn't seem to be used:
- $selmenu = ( isset($opt['breadcrumbs-selectedmenu']) && $opt['breadcrumbs-selectedmenu'] != '' ) ? $opt['breadcrumbs-selectedmenu'] : 0;
- $breadcrumb_array = array();
- if ( "page" == $on_front && 'post' == get_post_type() ) {
- $homeurl = get_permalink(get_option('page_on_front'));
- } else {
- $homeurl = get_bloginfo('url');
- }
- if ( $on_front == "page" && is_front_page() ) {
- $breadcrumb_array[] = array( 'title' => $hometitle, 'url' => '', 'class' => '', 'type' => 'home', 'ID' => null );
- } else if ( $on_front == "posts" && is_home() ) {
- $breadcrumb_array[] = array( 'title' => $hometitle, 'url' => '', 'class' => '', 'type' => 'home', 'ID' => null );
- } else if ( $on_front == "page" && is_home() ) {
- $breadcrumb_array[] = array( 'title' => $hometitle, 'url' => $homeurl, 'class' => '', 'type' => 'home', 'ID' => null );
- $breadcrumb_array[] = array( 'title' => $this->get_bc_title($blog_page), 'url' => '', 'class' => '', 'type' => get_post_type($blog_page), 'ID' => (int) $blog_page );
- } else if ( is_singular() ) {
- $breadcrumb_array[] = array( 'title' => $hometitle, 'url' => $homeurl, 'class' => '', 'type' => 'home', 'ID' => null );
- if ( $blog_page && 'page' == $on_front && 'post' == get_post_type() && ( !isset($opt['breadcrumbs-blog-remove']) || !$opt['breadcrumbs-blog-remove'] ) ) {
- $breadcrumb_array[] = array( 'title' => $this->get_bc_title($blog_page), 'url' => get_permalink($blog_page), 'class' => '', 'type' => get_post_type($blog_page), 'ID' => (int) $blog_page );
- }
- // This doesn't seem to be used:
- if( isset($opt['breadcrumbs-menus']) && $opt['breadcrumbs-menus'] = 'on'){
- $use_menu = $this->in_menu( $selmenu );
- }
- if ( function_exists('bbp_body_class') && count( bbp_body_class( array() ) ) > 1 ) {
- remove_filter('bbp_get_breadcrumb','__return_false');
- $bbp_bc_array = explode( ';;;;;', bbp_get_breadcrumb( ';;;;;' ) );
- if ( !empty($bbp_bc_array[0]) ) {
- foreach ( $bbp_bc_array as $bbp_bc ) {
- if ( preg_match( '/(<(a .*href="(?P<url>.*?)"( .*class="(?P<class>.*?)")?.*?)>)?(?P<title>.*)/', trim($bbp_bc), $bbp_pc_results ) ) {
- $breadcrumb_array[] = array ( 'title' => trim(strip_tags($bbp_pc_results['title'])), 'url' => $bbp_pc_results['url'], 'class' => $bbp_pc_results['class'], 'type' => 'bbpress', 'ID' => null );
- }
- }
- }
- add_filter('bbp_get_breadcrumb','__return_false');
- } else if( isset( $use_menu ) && $use_menu ){
- // This whole block doesn't seem to be used:
- $trail = $this->get_menu_trail();
- $trail = array_reverse ( $trail );
- $trailposts = array();
- for($t = 0; $t < count($trail); $t++){
- $trailposts[] = $this->get_post_for_menunode($trail[$t]);
- }
- for($t = 0; $t < count($trail); $t++){
- $bctitle = ( get_the_title( $trail[$t] ) == '' ) ? get_the_title( $trailposts[$t] ) : get_the_title( $trail[$t] );
- $breadcrumb_array[] = array( 'title' => $bctitle, 'url' => get_permalink( $trailposts[$t] ), 'class' => '', 'type' => get_post_type( $trailposts[$t] ), 'ID' => (int) $trailposts[$t] );
- }
- $breadcrumb_array[] = array( 'title' => $this->get_bc_title( $post->ID ), 'url' => '', 'class' => '', 'type' => get_post_type( $post->ID ), 'ID' => (int) $post->ID );
- } else {
- $post_type = get_post_type();
- if ( function_exists('get_post_type_archive_link') && get_post_type_archive_link( $post_type ) ) {
- if ( isset($options['bctitle-ptarchive-'.$post_type]) && '' != $options['bctitle-ptarchive-'.$post_type] ) {
- $archive_title = $options['bctitle-ptarchive-'.$post_type];
- } else {
- $post_type_obj = get_post_type_object( $post_type );
- //$archive_title = $post_type_obj->labels->menu_name;
- $archive_title = $post_type_obj->labels->name;
- }
- $breadcrumb_array[] = array( 'title' => $archive_title, 'url' => get_post_type_archive_link( $post_type ), 'class' => '', 'type' => $post_type, 'ID' => null );
- }
- if ( 0 == $post->post_parent ) {
- if ( isset( $opt['post_types-'.$post->post_type.'-maintax'] ) && $opt['post_types-'.$post->post_type.'-maintax'] != '0' ) {
- $main_tax = $opt['post_types-'.$post->post_type.'-maintax'];
- $terms = wp_get_object_terms( $post->ID, $main_tax, apply_filters( 'wp_seo_get_bc_taxonomy_args', array( 'orderby' => 'term_order' ) ) );
- if ( count($terms) > 0 ) {
- if ( is_taxonomy_hierarchical($main_tax) && $terms[0]->parent != 0 ) {
- $parents = $this->get_term_parents($terms[0], $main_tax);
- $parents = array_reverse($parents);
- foreach($parents as $parent) {
- $bctitle = wpseo_get_term_meta( $parent, $main_tax, 'bctitle' );
- if (!$bctitle) {
- $bctitle = $parent->name;
- }
- $breadcrumb_array[] = array( 'title' => $bctitle, 'url' => get_term_link( $parent, $main_tax ), 'class' => '', 'type' => $main_tax, 'ID' => (int) $parent->term_id );
- }
- }
- $bctitle = wpseo_get_term_meta( $terms[0], $main_tax, 'bctitle' );
- if (!$bctitle) {
- $bctitle = $terms[0]->name;
- }
- $breadcrumb_array[] = array( 'title' => $bctitle, 'url' => get_term_link($terms[0], $main_tax), 'class' => '', 'type' => $main_tax, 'ID' => (int) $terms[0]->term_id );
- }
- }
- $breadcrumb_array[] = array( 'title' => $this->get_bc_title( $post->ID ), 'url' => '', 'class' => '', 'type' => $post_type, 'ID' => (int) $post->ID );
- } 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);
- }
- $ancestors = array_reverse( $ancestors ); // Reverse the order so it's oldest to newest
- foreach ( $ancestors as $ancestor ) {
- $breadcrumb_array[] = array( 'title' => $this->get_bc_title( $ancestor ), 'url' => get_permalink($ancestor), 'class' => '', 'type' => get_post_type($ancestor), 'ID' => (int) $ancestor );
- }
- $breadcrumb_array[] = array( 'title' => $this->get_bc_title( $post->ID ), 'url' => '', 'class' => '', 'type' => $post_type, 'ID' => (int) $post->ID );
- }
- }
- } else {
- $breadcrumb_array[] = array( 'title' => $hometitle, 'url' => $homeurl, 'class' => '', 'type' => 'home', 'ID' => null );
- if ( !is_404() && $blog_page && 'page' == $on_front && 'post' == get_post_type() && ( !isset($opt['breadcrumbs-blog-remove']) || !$opt['breadcrumbs-blog-remove'] ) ) {
- $breadcrumb_array[] = array( 'title' => $this->get_bc_title($blog_page), 'url' => get_permalink($blog_page), 'class' => '', 'type' => get_post_type($blog_page), 'ID' => (int) $blog_page );
- }
- if ( function_exists('is_post_type_archive') && is_post_type_archive() && get_post_type() ) {
- $post_type = get_post_type();
- if ( isset($options['bctitle-ptarchive-'.$post_type]) && '' != $options['bctitle-ptarchive-'.$post_type] ) {
- $archive_title = $options['bctitle-ptarchive-'.$post_type];
- } else {
- $post_type_obj = get_post_type_object( $post_type );
- //$archive_title = $post_type_obj->labels->menu_name;
- $archive_title = $post_type_obj->labels->name;
- }
- $breadcrumb_array[] = array( 'title' => $archive_title, 'url' => '', 'class' => '', 'type' => $post_type, 'ID' => null );
- } else if ( is_tax() || is_tag() || is_category() ) {
- $term = $wp_query->get_queried_object();
- if ( isset($options['taxonomy-'.$term->taxonomy.'-ptparent']) && $options['taxonomy-'.$term->taxonomy.'-ptparent'] != '' ) {
- $post_type = $options['taxonomy-'.$term->taxonomy.'-ptparent'];
- if ( $blog_page && 'post' == $post_type && 'page' == $on_front ) {
- $breadcrumb_array[] = array( 'title' => $this->get_bc_title($blog_page), 'url' => get_permalink($blog_page), 'class' => '', 'type' => $post_type, 'ID' => $blog_page );
- } else {
- if ( isset($options['bctitle-ptarchive-'.$post_type]) && '' != $options['bctitle-ptarchive-'.$post_type] ) {
- $archive_title = $options['bctitle-ptarchive-'.$post_type];
- } else {
- $post_type_obj = get_post_type_object( $post_type );
- //$archive_title = $post_type_obj->labels->menu_name;
- $archive_title = $post_type_obj->labels->name;
- }
- $breadcrumb_array[] = array( 'title' => $archive_title, 'url' => get_post_type_archive_link( $post_type ), 'class' => '', 'type' => $post_type, 'ID' => null );
- }
- }
- if ( is_taxonomy_hierarchical($term->taxonomy) && $term->parent != 0 ) {
- $parents = $this->get_term_parents($term, $term->taxonomy);
- $parents = array_reverse( $parents );
- foreach($parents as $parent) {
- $bctitle = wpseo_get_term_meta( $parent, $term->taxonomy, 'bctitle' );
- if (!$bctitle) {
- $bctitle = $parent->name;
- }
- $breadcrumb_array[] = array( 'title' => $bctitle, 'url' => get_term_link( $parent, $term->taxonomy ), 'class' => '', 'type' => $parent->taxonomy, 'ID' => (int) $parent->term_id );
- }
- }
- $bctitle = wpseo_get_term_meta( $term, $term->taxonomy, 'bctitle' );
- if (!$bctitle) {
- $bctitle = $term->name;
- }
- if ($paged) {
- $breadcrumb_array[] = array( 'title' => $bctitle, 'url' => get_term_link( $term, $term->taxonomy ), 'class' => '', 'type' => $term->taxonomy, 'ID' => (int) $term->term_id );
- } else {
- $breadcrumb_array[] = array( 'title' => $bctitle, 'url' => '', 'class' => '', 'type' => $term->taxonomy, 'ID' => (int) $term->term_id );
- }
- } else if ( is_date() ) {
- if ( isset($opt['breadcrumbs-archiveprefix']) ) {
- $bc = $opt['breadcrumbs-archiveprefix'];
- } else {
- $bc = __('Archives for','wordpress-seo');
- }
- if ( is_day() ) {
- global $wp_locale;
- $breadcrumb_array[] = array( 'title' => $wp_locale->get_month( get_query_var('monthnum') ).' '.get_query_var('year'), 'url' => get_month_link( get_query_var('year'), get_query_var('monthnum') ), 'class' => '', 'type' => 'date', 'ID' => null );
- $breadcrumb_array[] = array( 'title' => $bc." ".get_the_date(), 'url' => '', 'class' => '', 'type' => 'date', 'ID' => null );
- } else if ( is_month() ) {
- $breadcrumb_array[] = array( 'title' => $bc." ".single_month_title(' ',false), 'url' => '', 'class' => '', 'type' => 'date', 'ID' => null );
- } else if ( is_year() ) {
- $breadcrumb_array[] = array( 'title' => $bc." ".get_query_var('year'), 'url' => '', 'class' => '', 'type' => 'date', 'ID' => null );
- }
- } elseif ( is_author() ) {
- if ( isset($opt['breadcrumbs-archiveprefix']) ) {
- $bc = $opt['breadcrumbs-archiveprefix'];
- } else {
- $bc = __('Archives for','wordpress-seo');
- }
- $user = $wp_query->get_queried_object();
- $breadcrumb_array[] = array( 'title' => $bc." ".$user->display_name, 'url' => '', 'class' => '', 'type' => 'author', 'ID' => $user->ID );
- } elseif ( is_search() ) {
- if ( isset($opt['breadcrumbs-searchprefix']) && $opt['breadcrumbs-searchprefix'] != '' ) {
- $bc = $opt['breadcrumbs-searchprefix'];
- } else {
- $bc = __('You searched for','wordpress-seo');
- }
- $breadcrumb_array[] = array( 'title' => $bc.' "'.stripslashes(strip_tags(get_search_query())).'"', 'url' => '', 'class' => '', 'type' => 'search', 'ID' => null );
- } elseif ( isset( $wp_query->query_vars['bbp_topic_tag'] ) ) {
- remove_filter('bbp_get_breadcrumb','__return_false');
- $bbp_bc_array = explode( ';;;;;', bbp_get_breadcrumb( ';;;;;' ) );
- if ( !empty($bbp_bc_array[0]) ) {
- foreach ( $bbp_bc_array as $bbp_bc ) {
- if ( preg_match( '/(<(a .*href="(?P<url>.*?)"( .*class="(?P<class>.*?)")?.*?)>)?(?P<title>.*)/', trim($bbp_bc), $bbp_pc_results ) ) {
- $breadcrumb_array[] = array ( 'title' => trim(strip_tags($bbp_pc_results['title'])), 'url' => $bbp_pc_results['url'], 'class' => $bbp_pc_results['class'], 'type' => 'bbpress', 'ID' => null );
- }
- }
- }
- add_filter('bbp_get_breadcrumb','__return_false');
- } elseif ( is_404() ) {
- if ( isset($opt['breadcrumbs-404crumb']) && $opt['breadcrumbs-404crumb'] != '' ) {
- $crumb404 = $opt['breadcrumbs-404crumb'];
- } else {
- $crumb404 = __('Error 404: Page not found','wordpress-seo');
- }
- $breadcrumb_array[] = array ( 'title' => $crumb404, 'url' => '', 'class' => '', 'type' => '404-not-found', 'ID' => null );
- }
- }
- $breadcrumb_array = apply_filters( 'wp_seo_get_bc_ancestors', $breadcrumb_array );
- $output = '';
- if ( !empty($breadcrumb_array) ) {
- $output .= $prefix;
- if ( isset($opt['breadcrumbs-prefix']) && $opt['breadcrumbs-prefix'] != "" ) {
- $output .= $opt['breadcrumbs-prefix'].' ';
- }
- $breadcrumb_total = count( $breadcrumb_array ) - 1; // Since arrays start at 0.
- for ( $i = 0 ; $i <= $breadcrumb_total ; $i++ ) {
- $breadcrumb = $breadcrumb_array[$i];
- $pre_out = $post_out = '';
- $mid_out = $breadcrumb['title'];
- // We don't want search engines displaying the home link in the snippet breadcrumb. Also,
- // a breadcrumb DIV for the very last item (the current page) is ignored. So we deal with
- // the special cases:
- if ( ( $i == 0 && $breadcrumb['type'] != 'home' ) || ( $i > 0 && $i < $breadcrumb_total ) ) {
- $pre_out .= '<div';
- if ( ( $i == 1 && $breadcrumb_array[0]['type'] != 'home' ) || $i > 1 ) {
- $pre_out .= ' itemprop="child"';
- }
- $pre_out .= ' itemscope itemtype="http://data-vocabulary.org/Breadcrumb" style="display: inline;">';
- $mid_out = '<span itemprop="title">'.$mid_out.'</span>';
- $suffix = '</div>'.$suffix;
- }
- if ( $breadcrumb['url'] ) {
- $pre_out .= '<a href="'.esc_url($breadcrumb['url']).'"';
- if ( $breadcrumb['class'] ) {
- $pre_out .= ' class="'.esc_attr($breadcrumb['class']).'"';
- }
- if ( $i == 0 && $breadcrumb['type'] != 'home' ) {
- $pre_out .= ' itemprop="url"';
- }
- $pre_out .= '>';
- $post_out .= '</a>';
- }
- if ( $i < $breadcrumb_total ) {
- $post_out .= ' '.$sep.' ';
- } else {
- $mid_out = $this->bold_or_not( $mid_out );
- }
- $output .= $pre_out.$mid_out.$post_out;
- }
- $output .= $suffix;
- }
- if ($display) {
- echo $output;
- return true;
- } else {
- return $output;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement