2011-12-12 11:35:54 +00:00
< ? php
/**
2012-08-14 18:05:45 +00:00
* Shop breadcrumb
*
* @ author WooThemes
* @ package WooCommerce / Templates
* @ version 1.6 . 4
2011-12-12 11:35:54 +00:00
*/
2012-10-15 10:57:58 +00:00
if ( ! defined ( 'ABSPATH' ) ) exit ; // Exit if accessed directly
2012-02-03 16:17:35 +00:00
global $post , $wp_query ;
2011-12-12 11:35:54 +00:00
2012-11-27 16:22:47 +00:00
if ( ! $home )
2012-08-25 11:08:03 +00:00
$home = _x ( 'Home' , 'breadcrumb' , 'woocommerce' );
2011-12-12 11:35:54 +00:00
$home_link = home_url ();
2012-08-25 11:08:03 +00:00
if ( get_option ( 'woocommerce_prepend_shop_page_to_urls' ) == " yes " && woocommerce_get_page_id ( 'shop' ) && get_option ( 'page_on_front' ) !== woocommerce_get_page_id ( 'shop' ) )
2012-01-06 17:14:31 +00:00
$prepend = $before . '<a href="' . get_permalink ( woocommerce_get_page_id ( 'shop' ) ) . '">' . get_the_title ( woocommerce_get_page_id ( 'shop' ) ) . '</a> ' . $after . $delimiter ;
2012-08-25 11:08:03 +00:00
else
$prepend = '' ;
2011-12-12 11:35:54 +00:00
2012-08-25 11:08:03 +00:00
if ( ( ! is_home () && ! is_front_page () && ! ( is_post_type_archive () && get_option ( 'page_on_front' ) == woocommerce_get_page_id ( 'shop' ) ) ) || is_paged () ) {
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
echo $wrap_before . $before . '<a class="home" href="' . $home_link . '">' . $home . '</a> ' . $after . $delimiter ;
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
if ( is_category () ) {
2012-08-14 18:05:45 +00:00
2011-12-12 11:35:54 +00:00
$cat_obj = $wp_query -> get_queried_object ();
2012-08-25 11:08:03 +00:00
$this_category = get_category ( $cat_obj -> term_id );
2012-11-27 16:22:47 +00:00
2012-08-25 11:08:03 +00:00
if ( $this_category -> parent != 0 ) {
2011-12-12 11:35:54 +00:00
$parent_category = get_category ( $this_category -> parent );
echo get_category_parents ( $parent_category , TRUE , $delimiter );
2012-08-25 11:08:03 +00:00
}
2012-11-27 16:22:47 +00:00
2012-08-25 11:08:03 +00:00
echo $before . single_cat_title ( '' , false ) . $after ;
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
} elseif ( is_tax ( 'product_cat' ) ) {
2012-08-14 18:05:45 +00:00
2012-02-01 23:35:24 +00:00
echo $prepend ;
2011-12-12 11:35:54 +00:00
$term = get_term_by ( 'slug' , get_query_var ( 'term' ), get_query_var ( 'taxonomy' ) );
2012-08-14 18:05:45 +00:00
2011-12-12 11:35:54 +00:00
$parents = array ();
$parent = $term -> parent ;
2012-08-25 11:08:03 +00:00
while ( $parent ) {
2011-12-12 11:35:54 +00:00
$parents [] = $parent ;
2012-08-25 11:08:03 +00:00
$new_parent = get_term_by ( 'id' , $parent , get_query_var ( 'taxonomy' ) );
2011-12-12 11:35:54 +00:00
$parent = $new_parent -> parent ;
2012-08-25 11:08:03 +00:00
}
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
if ( ! empty ( $parents ) ) {
$parents = array_reverse ( $parents );
foreach ( $parents as $parent ) {
2011-12-12 11:35:54 +00:00
$item = get_term_by ( 'id' , $parent , get_query_var ( 'taxonomy' ));
2012-10-16 15:35:16 +00:00
echo $before . '<a href="' . get_term_link ( $item -> slug , 'product_cat' ) . '">' . esc_html ( $item -> name ) . '</a>' . $after . $delimiter ;
2012-08-25 11:08:03 +00:00
}
}
2012-08-14 18:05:45 +00:00
2011-12-12 11:35:54 +00:00
$queried_object = $wp_query -> get_queried_object ();
2012-10-16 15:35:16 +00:00
echo $before . esc_html ( $queried_object -> name ) . $after ;
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
} elseif ( is_tax ( 'product_tag' ) ) {
2012-08-14 18:05:45 +00:00
2011-12-12 11:35:54 +00:00
$queried_object = $wp_query -> get_queried_object ();
2012-10-16 09:45:33 +00:00
echo $prepend . $before . __ ( 'Products tagged “' , 'woocommerce' ) . $queried_object -> name . '”' . $after ;
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
} elseif ( is_day () ) {
2012-08-14 18:05:45 +00:00
2011-12-12 11:35:54 +00:00
echo $before . '<a href="' . get_year_link ( get_the_time ( 'Y' )) . '">' . get_the_time ( 'Y' ) . '</a>' . $after . $delimiter ;
echo $before . '<a href="' . get_month_link ( get_the_time ( 'Y' ), get_the_time ( 'm' )) . '">' . get_the_time ( 'F' ) . '</a>' . $after . $delimiter ;
echo $before . get_the_time ( 'd' ) . $after ;
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
} elseif ( is_month () ) {
2012-08-14 18:05:45 +00:00
2011-12-12 11:35:54 +00:00
echo $before . '<a href="' . get_year_link ( get_the_time ( 'Y' )) . '">' . get_the_time ( 'Y' ) . '</a>' . $after . $delimiter ;
echo $before . get_the_time ( 'F' ) . $after ;
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
} elseif ( is_year () ) {
2012-08-14 18:05:45 +00:00
2011-12-12 11:35:54 +00:00
echo $before . get_the_time ( 'Y' ) . $after ;
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
} elseif ( is_post_type_archive ( 'product' ) && get_option ( 'page_on_front' ) !== woocommerce_get_page_id ( 'shop' ) ) {
2012-08-14 18:05:45 +00:00
2012-10-18 09:33:02 +00:00
$_name = woocommerce_get_page_id ( 'shop' ) ? get_the_title ( woocommerce_get_page_id ( 'shop' ) ) : '' ;
2012-11-27 16:22:47 +00:00
2012-10-18 09:33:02 +00:00
if ( ! $_name ) {
$product_post_type = get_post_type_object ( 'product' );
$_name = $product_post_type -> labels -> singular_name ;
}
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
if ( is_search () ) {
2012-08-14 18:05:45 +00:00
2012-10-16 09:45:33 +00:00
echo $before . '<a href="' . get_post_type_archive_link ( 'product' ) . '">' . $_name . '</a>' . $delimiter . __ ( 'Search results for “' , 'woocommerce' ) . get_search_query () . '”' . $after ;
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
} elseif ( is_paged () ) {
2012-08-14 18:05:45 +00:00
2012-08-25 10:39:00 +00:00
echo $before . '<a href="' . get_post_type_archive_link ( 'product' ) . '">' . $_name . '</a>' . $after ;
2012-08-25 11:08:03 +00:00
} else {
2012-11-27 16:22:47 +00:00
2012-08-25 10:25:43 +00:00
echo $before . $_name . $after ;
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
}
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
} elseif ( is_single () && ! is_attachment () ) {
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
if ( get_post_type () == 'product' ) {
2012-08-14 18:05:45 +00:00
2011-12-12 11:35:54 +00:00
echo $prepend ;
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
if ( $terms = wp_get_object_terms ( $post -> ID , 'product_cat' ) ) {
$term = current ( $terms );
$parents = array ();
$parent = $term -> parent ;
2012-11-27 16:22:47 +00:00
2012-08-25 11:08:03 +00:00
while ( $parent ) {
$parents [] = $parent ;
$new_parent = get_term_by ( 'id' , $parent , 'product_cat' );
$parent = $new_parent -> parent ;
}
2012-11-27 16:22:47 +00:00
2012-08-25 11:08:03 +00:00
if ( ! empty ( $parents ) ) {
$parents = array_reverse ( $parents );
foreach ( $parents as $parent ) {
$item = get_term_by ( 'id' , $parent , 'product_cat' );
echo $before . '<a href="' . get_term_link ( $item -> slug , 'product_cat' ) . '">' . $item -> name . '</a>' . $after . $delimiter ;
}
}
2012-11-27 16:22:47 +00:00
2012-08-25 11:08:03 +00:00
echo $before . '<a href="' . get_term_link ( $term -> slug , 'product_cat' ) . '">' . $term -> name . '</a>' . $after . $delimiter ;
2012-11-27 16:22:47 +00:00
2012-08-25 11:08:03 +00:00
}
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
echo $before . get_the_title () . $after ;
} elseif ( get_post_type () != 'post' ) {
2012-11-27 16:22:47 +00:00
2012-08-25 11:08:03 +00:00
$post_type = get_post_type_object ( get_post_type () );
$slug = $post_type -> rewrite ;
echo $before . '<a href="' . get_post_type_archive_link ( get_post_type () ) . '">' . $post_type -> labels -> singular_name . '</a>' . $after . $delimiter ;
echo $before . get_the_title () . $after ;
2012-11-27 16:22:47 +00:00
2012-08-25 11:08:03 +00:00
} else {
2012-11-27 16:22:47 +00:00
2012-08-25 11:08:03 +00:00
$cat = current ( get_the_category () );
echo get_category_parents ( $cat , true , $delimiter );
echo $before . get_the_title () . $after ;
2012-11-27 16:22:47 +00:00
2012-08-25 11:08:03 +00:00
}
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
} elseif ( is_404 () ) {
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
echo $before . __ ( 'Error 404' , 'woocommerce' ) . $after ;
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
} elseif ( ! is_single () && ! is_page () && get_post_type () != 'post' ) {
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
$post_type = get_post_type_object ( get_post_type () );
2012-11-27 16:22:47 +00:00
2012-08-25 11:08:03 +00:00
if ( $post_type )
echo $before . $post_type -> labels -> singular_name . $after ;
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
} elseif ( is_attachment () ) {
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
$parent = get_post ( $post -> post_parent );
2012-11-27 16:22:47 +00:00
$cat = get_the_category ( $parent -> ID );
2012-08-25 11:08:03 +00:00
$cat = $cat [ 0 ];
echo get_category_parents ( $cat , true , '' . $delimiter );
echo $before . '<a href="' . get_permalink ( $parent ) . '">' . $parent -> post_title . '</a>' . $after . $delimiter ;
2011-12-12 11:35:54 +00:00
echo $before . get_the_title () . $after ;
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
} elseif ( is_page () && ! $post -> post_parent ) {
2012-08-14 18:05:45 +00:00
2011-12-12 11:35:54 +00:00
echo $before . get_the_title () . $after ;
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
} elseif ( is_page () && $post -> post_parent ) {
2012-08-14 18:05:45 +00:00
2011-12-12 11:35:54 +00:00
$parent_id = $post -> post_parent ;
$breadcrumbs = array ();
2012-11-27 16:22:47 +00:00
2012-08-25 11:08:03 +00:00
while ( $parent_id ) {
$page = get_page ( $parent_id );
$breadcrumbs [] = '<a href="' . get_permalink ( $page -> ID ) . '">' . get_the_title ( $page -> ID ) . '</a>' ;
2011-12-12 11:35:54 +00:00
$parent_id = $page -> post_parent ;
}
2012-11-27 16:22:47 +00:00
2012-08-25 11:08:03 +00:00
$breadcrumbs = array_reverse ( $breadcrumbs );
2012-11-27 16:22:47 +00:00
2012-08-25 11:08:03 +00:00
foreach ( $breadcrumbs as $crumb )
2011-12-12 11:35:54 +00:00
echo $crumb . '' . $delimiter ;
2012-08-25 11:08:03 +00:00
2011-12-12 11:35:54 +00:00
echo $before . get_the_title () . $after ;
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
} elseif ( is_search () ) {
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
echo $before . __ ( 'Search results for “' , 'woocommerce' ) . get_search_query () . '”' . $after ;
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
} elseif ( is_tag () ) {
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
echo $before . __ ( 'Posts tagged “' , 'woocommerce' ) . single_tag_title ( '' , false ) . '”' . $after ;
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
} elseif ( is_author () ) {
2012-08-14 18:05:45 +00:00
2011-12-12 11:35:54 +00:00
$userdata = get_userdata ( $author );
2012-08-25 11:08:03 +00:00
echo $before . __ ( 'Author:' , 'woocommerce' ) . ' ' . $userdata -> display_name . $after ;
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
}
2012-08-14 18:05:45 +00:00
2012-08-25 11:08:03 +00:00
if ( get_query_var ( 'paged' ) )
echo ' (' . __ ( 'Page' , 'woocommerce' ) . ' ' . get_query_var ( 'paged' ) . ')' ;
2012-08-14 18:05:45 +00:00
2011-12-12 11:35:54 +00:00
echo $wrap_after ;
2012-08-25 11:08:03 +00:00
}