Function Reference: geodir_breadcrumb
Summary
Main function that generates breadcrumb for all pages.
Global Values
- $wp_query
- (object) (required) WordPress Query object.
- Default: None
- $post
- (object) (required) The current post object.
- Default: None
- $gd_session
- (object) (required) GeoDirectory Session object.
- Default: None
Package
GeoDirectory
Change Log
Since: 1.0.0
1.5.7 Changes for the neighbourhood system improvement.
1.6.16 Fix: Breadcrumb formatting issue with the neighbourhood name.
Filters
‘geodir_breadcrumb_separator’ [Line: 1258]
‘geodir_breadcrumb’ [Line: 1609]
Source File
geodir_breadcrumb() is located in geodirectory-functions/general_functions.php [Line: 1250]
Source Code
function geodir_breadcrumb() {
global $wp_query, $geodir_add_location_url;
/**
* Filter breadcrumb separator.
*
* @since 1.0.0
*/
$separator = apply_filters( 'geodir_breadcrumb_separator', ' > ' );
if ( ! geodir_is_page( 'home' ) ) {
$breadcrumb = '';
$url_categoris = '';
$breadcrumb .= '';
/**
* Filter breadcrumb's first link.
*
* @since 1.0.0
*/
$breadcrumb .= '- ' . apply_filters( 'geodir_breadcrumb_first_link', '' . __( 'Home', 'geodirectory' ) . '' ) . '
';
$gd_post_type = geodir_get_current_posttype();
$post_type_info = get_post_type_object( $gd_post_type );
remove_filter( 'post_type_archive_link', 'geodir_get_posttype_link' );
$listing_link = get_post_type_archive_link( $gd_post_type );
add_filter( 'post_type_archive_link', 'geodir_get_posttype_link', 10, 2 );
$listing_link = rtrim( $listing_link, '/' );
$listing_link .= '/';
$post_type_for_location_link = $listing_link;
$location_terms = geodir_get_current_location_terms( 'query_vars', $gd_post_type );
global $wp, $gd_session;
$location_link = $post_type_for_location_link;
if ( geodir_is_page( 'detail' ) || geodir_is_page( 'listing' ) ) {
global $post;
$location_manager = defined( 'POST_LOCATION_TABLE' ) ? true : false;
$neighbourhood_active = $location_manager && get_option( 'location_neighbourhoods' ) ? true : false;
if ( geodir_is_page( 'detail' ) && isset( $post->country_slug ) ) {
$location_terms = array(
'gd_country' => $post->country_slug,
'gd_region' => $post->region_slug,
'gd_city' => $post->city_slug
);
if ( $neighbourhood_active && ! empty( $location_terms['gd_city'] ) && $gd_ses_neighbourhood = $gd_session->get( 'gd_neighbourhood' ) ) {
$location_terms['gd_neighbourhood'] = $gd_ses_neighbourhood;
}
}
$geodir_show_location_url = get_option( 'geodir_show_location_url' );
$hide_url_part = array();
if ( $location_manager ) {
$hide_country_part = get_option( 'geodir_location_hide_country_part' );
$hide_region_part = get_option( 'geodir_location_hide_region_part' );
if ( $hide_region_part && $hide_country_part ) {
$hide_url_part = array( 'gd_country', 'gd_region' );
} else if ( $hide_region_part && ! $hide_country_part ) {
$hide_url_part = array( 'gd_region' );
} else if ( ! $hide_region_part && $hide_country_part ) {
$hide_url_part = array( 'gd_country' );
}
}
$hide_text_part = array();
if ( $geodir_show_location_url == 'country_city' ) {
$hide_text_part = array( 'gd_region' );
if ( isset( $location_terms['gd_region'] ) && ! $location_manager ) {
unset( $location_terms['gd_region'] );
}
} else if ( $geodir_show_location_url == 'region_city' ) {
$hide_text_part = array( 'gd_country' );
if ( isset( $location_terms['gd_country'] ) && ! $location_manager ) {
unset( $location_terms['gd_country'] );
}
} else if ( $geodir_show_location_url == 'city' ) {
$hide_text_part = array( 'gd_country', 'gd_region' );
if ( isset( $location_terms['gd_country'] ) && ! $location_manager ) {
unset( $location_terms['gd_country'] );
}
if ( isset( $location_terms['gd_region'] ) && ! $location_manager ) {
unset( $location_terms['gd_region'] );
}
}
$is_location_last = '';
$is_taxonomy_last = '';
$breadcrumb .= '- ';
if ( get_query_var( $gd_post_type . 'category' ) ) {
$gd_taxonomy = $gd_post_type . 'category';
} elseif ( get_query_var( $gd_post_type . '_tags' ) ) {
$gd_taxonomy = $gd_post_type . '_tags';
}
$breadcrumb .= $separator . '' . __( geodir_utf8_ucfirst( $post_type_info->label ), 'geodirectory' ) . '';
if ( ! empty( $gd_taxonomy ) || geodir_is_page( 'detail' ) ) {
$is_location_last = false;
} else {
$is_location_last = true;
}
if ( ! empty( $gd_taxonomy ) && geodir_is_page( 'listing' ) ) {
$is_taxonomy_last = true;
} else {
$is_taxonomy_last = false;
}
if ( ! empty( $location_terms ) ) {
$geodir_get_locations = function_exists( 'get_actual_location_name' ) ? true : false;
foreach ( $location_terms as $key => $location_term ) {
if ( $location_term != '' ) {
if ( ! empty( $hide_url_part ) && in_array( $key, $hide_url_part ) ) { // Hide location part from url & breadcrumb.
continue;
}
$gd_location_link_text = preg_replace( '/-(\d+)$/', '', $location_term );
$gd_location_link_text = preg_replace( '/[_-]/', ' ', $gd_location_link_text );
$gd_location_link_text = geodir_utf8_ucfirst( $gd_location_link_text );
$location_term_actual_country = '';
$location_term_actual_region = '';
$location_term_actual_city = '';
$location_term_actual_neighbourhood = '';
if ( $geodir_get_locations ) {
if ( $key == 'gd_country' ) {
$location_term_actual_country = get_actual_location_name( 'country', $location_term, true );
} else if ( $key == 'gd_region' ) {
$location_term_actual_region = get_actual_location_name( 'region', $location_term, true );
} else if ( $key == 'gd_city' ) {
$location_term_actual_city = get_actual_location_name( 'city', $location_term, true );
} else if ( $key == 'gd_neighbourhood' ) {
$location_term_actual_neighbourhood = get_actual_location_name( 'neighbourhood', $location_term, true );
}
} else {
$location_info = geodir_get_location();
if ( ! empty( $location_info ) && isset( $location_info->location_id ) ) {
if ( $key == 'gd_country' ) {
$location_term_actual_country = __( $location_info->country, 'geodirectory' );
} else if ( $key == 'gd_region' ) {
$location_term_actual_region = __( $location_info->region, 'geodirectory' );
} else if ( $key == 'gd_city' ) {
$location_term_actual_city = __( $location_info->city, 'geodirectory' );
}
}
}
if ( $is_location_last && $key == 'gd_country' && ! ( isset( $location_terms['gd_region'] ) && $location_terms['gd_region'] != '' ) && ! ( isset( $location_terms['gd_city'] ) && $location_terms['gd_city'] != '' ) ) {
$breadcrumb .= $location_term_actual_country != '' ? $separator . $location_term_actual_country : $separator . $gd_location_link_text;
} else if ( $is_location_last && $key == 'gd_region' && ! ( isset( $location_terms['gd_city'] ) && $location_terms['gd_city'] != '' ) ) {
$breadcrumb .= $location_term_actual_region != '' ? $separator . $location_term_actual_region : $separator . $gd_location_link_text;
} else if ( $is_location_last && $key == 'gd_city' && empty( $location_terms['gd_neighbourhood'] ) ) {
$breadcrumb .= $location_term_actual_city != '' ? $separator . $location_term_actual_city : $separator . $gd_location_link_text;
} else if ( $is_location_last && $key == 'gd_neighbourhood' ) {
$breadcrumb .= $location_term_actual_neighbourhood != '' ? $separator . $location_term_actual_neighbourhood : $separator . $gd_location_link_text;
} else {
if ( get_option( 'permalink_structure' ) != '' ) {
$location_link .= $location_term . '/';
} else {
$location_link .= "&$key=" . $location_term;
}
if ( $key == 'gd_country' && $location_term_actual_country != '' ) {
$gd_location_link_text = $location_term_actual_country;
} else if ( $key == 'gd_region' && $location_term_actual_region != '' ) {
$gd_location_link_text = $location_term_actual_region;
} else if ( $key == 'gd_city' && $location_term_actual_city != '' ) {
$gd_location_link_text = $location_term_actual_city;
} else if ( $key == 'gd_neighbourhood' && $location_term_actual_neighbourhood != '' ) {
$gd_location_link_text = $location_term_actual_neighbourhood;
}
/*
if (geodir_is_page('detail') && !empty($hide_text_part) && in_array($key, $hide_text_part)) {
continue;
}
*/
$breadcrumb .= $separator . '' . $gd_location_link_text . '';
}
}
}
}
if ( ! empty( $gd_taxonomy ) ) {
$term_index = 1;
//if(get_option('geodir_add_categories_url'))
{
if ( get_query_var( $gd_post_type . '_tags' ) ) {
$cat_link = $listing_link . 'tags/';
} else {
$cat_link = $listing_link;
}
foreach ( $location_terms as $key => $location_term ) {
if ( $location_manager && in_array( $key, $hide_url_part ) ) {
continue;
}
if ( $location_term != '' ) {
if ( get_option( 'permalink_structure' ) != '' ) {
$cat_link .= $location_term . '/';
}
}
}
$term_array = explode( "/", trim( $wp_query->query[ $gd_taxonomy ], "/" ) );
foreach ( $term_array as $term ) {
$term_link_text = preg_replace( '/-(\d+)$/', '', $term );
$term_link_text = preg_replace( '/[_-]/', ' ', $term_link_text );
// get term actual name
$term_info = get_term_by( 'slug', $term, $gd_taxonomy, 'ARRAY_A' );
if ( ! empty( $term_info ) && isset( $term_info['name'] ) && $term_info['name'] != '' ) {
$term_link_text = urldecode( $term_info['name'] );
} else {
continue;
//$term_link_text = wp_strip_all_tags(geodir_ucwords(urldecode($term_link_text)));
}
if ( $term_index == count( $term_array ) && $is_taxonomy_last ) {
$breadcrumb .= $separator . $term_link_text;
} else {
$cat_link .= $term . '/';
$breadcrumb .= $separator . '' . $term_link_text . '';
}
$term_index ++;
}
}
}
if ( geodir_is_page( 'detail' ) ) {
$breadcrumb .= $separator . get_the_title();
}
$breadcrumb .= '
';
} elseif ( geodir_is_page( 'author' ) ) {
$dashboard_post_type = isset($_REQUEST['stype']) ? sanitize_text_field($_REQUEST['stype']) : $gd_post_type;
$user_id = get_current_user_id();
$author_link = get_author_posts_url( $user_id );
$default_author_link = geodir_getlink( $author_link, array(
'geodir_dashbord' => 'true',
'stype' => $dashboard_post_type
), false );
/**
* Filter author page link.
*
* @since 1.0.0
*
* @param string $default_author_link Default author link.
* @param int $user_id Author ID.
*/
$default_author_link = apply_filters( 'geodir_dashboard_author_link', $default_author_link, $user_id );
$breadcrumb .= '- ';
$breadcrumb .= $separator . '' . __( 'My Dashboard', 'geodirectory' ) . '';
if ( isset( $_REQUEST['list'] ) ) {
$author_link = geodir_getlink( $author_link, array(
'geodir_dashbord' => 'true',
'stype' => $_REQUEST['stype']
), false );
/**
* Filter author page link.
*
* @since 1.0.0
*
* @param string $author_link Author page link.
* @param int $user_id Author ID.
* @param string $_REQUEST ['stype'] Post type.
*/
$author_link = apply_filters( 'geodir_dashboard_author_link', $author_link, $user_id, $_REQUEST['stype'] );
$breadcrumb .= $separator . '' . __( geodir_utf8_ucfirst( $post_type_info->label ), 'geodirectory' ) . '';
if($_REQUEST['list']=='favourite'){
$breadcrumb .= $separator . MY_FAVOURITE_TEXT;
}
} else {
$breadcrumb .= $separator . __( geodir_utf8_ucfirst( $post_type_info->label ), 'geodirectory' );
}
$breadcrumb .= '
';
} elseif ( is_category() || is_single() ) {
$category = get_the_category();
if ( is_category() ) {
$breadcrumb .= '- ' . $separator . $category[0]->cat_name . '
';
}
if ( is_single() ) {
$breadcrumb .= '- ' . $separator . '' . $category[0]->cat_name . '
';
$breadcrumb .= '- ' . $separator . get_the_title() . '
';
}
/* End of my version ##################################################### */
} else if ( is_page() ) {
$page_title = get_the_title();
if ( geodir_is_page( 'location' ) ) {
$location_page_id = geodir_location_page_id();
$loc_post = get_post( $location_page_id );
$post_name = $loc_post->post_name;
$slug = ucwords( str_replace( '-', ' ', $post_name ) );
$page_title = ! empty( $slug ) ? $slug : __( 'Location', 'geodirectory' );
}
$breadcrumb .= '- ' . $separator;
$breadcrumb .= stripslashes_deep( $page_title );
$breadcrumb .= '
';
} else if ( is_tag() ) {
$breadcrumb .= "- " . $separator . single_tag_title( '', false ) . '
';
} else if ( is_day() ) {
$breadcrumb .= "- " . $separator . __( " Archive for", 'geodirectory' ) . " ";
the_time( 'F jS, Y' );
$breadcrumb .= '
';
} else if ( is_month() ) {
$breadcrumb .= "- " . $separator . __( " Archive for", 'geodirectory' ) . " ";
the_time( 'F, Y' );
$breadcrumb .= '
';
} else if ( is_year() ) {
$breadcrumb .= "- " . $separator . __( " Archive for", 'geodirectory' ) . " ";
the_time( 'Y' );
$breadcrumb .= '
';
} else if ( is_author() ) {
$breadcrumb .= "- " . $separator . __( " Author Archive", 'geodirectory' );
$breadcrumb .= '
';
} else if ( isset( $_GET['paged'] ) && ! empty( $_GET['paged'] ) ) {
$breadcrumb .= "- " . $separator . __( "Blog Archives", 'geodirectory' );
$breadcrumb .= '
';
} else if ( is_search() ) {
$breadcrumb .= "- " . $separator . __( " Search Results", 'geodirectory' );
$breadcrumb .= '
';
}
$breadcrumb .= '
';
/**
* Filter breadcrumb html output.
*
* @since 1.0.0
*
* @param string $breadcrumb Breadcrumb HTML.
* @param string $separator Breadcrumb separator.
*/
echo $breadcrumb = apply_filters( 'geodir_breadcrumb', $breadcrumb, $separator );
}
}