functions - if statement for parent and child - wordpress

I've got following php function:
if ( ! function_exists('meteorite_sitebranding') ):
function meteorite_sitebranding() {
$logo_light = get_theme_mod( 'logo_light', '' );
$has_custom_logo = has_custom_logo();
if ( $has_custom_logo || $logo_light) {
if ( function_exists( 'the_custom_logo' ) && has_custom_logo() && is_front_page() || is_home() ) {
the_custom_logo();
}
elseif ( function_exists( 'the_custom_logo' ) && has_custom_logo() ) {
echo '<img src="logo_color.png" class="custom-logo" alt="Auplo" itemprop="logo" />';
}
elseif ( $logo_light ) {
echo '<img class="site-logo light" src="' . esc_url($logo_light) . '" alt="' . esc_attr(get_bloginfo('name')) . '" />';
}
} else {
echo '<div class="site-brand">';
if ( is_front_page() && is_home() ) :
echo '<h1 class="site-title">' . get_bloginfo('name', 'display') . '</h1>';
else :
echo '<p class="site-title">' . get_bloginfo('name', 'display') . '</p>';
endif;
echo '<p class="site-description">' . get_bloginfo('description', 'display') . '</p>';
echo '</div>'; // /.site-brand
}
}
endif;
the function works well. But i would like to finetune it a bit. My question is related to part:
if ( function_exists( 'the_custom_logo' ) && has_custom_logo() &&
is_front_page() || is_home() )
How can i add as a part of statement the condition of OR is_page('destination') and include all childs of that page? so e.g. Ive got page
Destination
+ New York
+ Warsaw
+ Dublin
+ Dubai
and i would like to cover all those pages. I've tried doing something like:
|| is_page('destination') || is_child('destination') but simply it doesnt work..
thanks!

You could use this
function is_child($pageID) { // In functions.php
global $post;
if( is_page() && ($post->post_parent==$pageID) ) {
return true;
} else {
return false;
}
}
if(is_child(123)) { // in your template
echo "Child page of 123";
}

Related

How to customize WooCommerce Breadcrumbs [duplicate]

I'm using the following function to remove the product title from the breadcrumbs displayed on the product page:
add_filter( 'woocommerce_get_breadcrumb', 'ed_change_breadcrumb' );
function ed_change_breadcrumb( $breadcrumb ) {
if(is_singular()){
array_pop($breadcrumb);
}
return $breadcrumb;
}
It works in that it does remove the title, but it also stops the last category/sub-category from being a hyperlink. How can I fix that?
For example:
Original breadcrumb
<a>Home</a> / <a>Category</a> / <a>Sub Category</a> / Product Title
Result of the above function
<a>Home</a> / <a>Category</a> / Sub Category
I need the Sub Category to still be clickable after removing the product title from the breadcrumbs.
Thanks
Your code works but the last element in the breadcrumbs never contains a link through the code used in global/breadcrumb.php template file on line 34
This template can be overridden by copying it to yourtheme/woocommerce/global/breadcrumb.php.
So you can remove your filter hook and apply the following code in the template file so that it provides a link to the last element when is_product() is true
Note: is_product() - Returns true on a single product page. Wrapper for is_singular()
Replace
if ( ! empty( $breadcrumb ) ) {
echo $wrap_before;
foreach ( $breadcrumb as $key => $crumb ) {
echo $before;
if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) {
echo '' . esc_html( $crumb[0] ) . '';
} else {
echo esc_html( $crumb[0] );
}
echo $after;
if ( sizeof( $breadcrumb ) !== $key + 1 ) {
echo $delimiter;
}
}
echo $wrap_after;
}
With
if ( ! empty( $breadcrumb ) ) {
echo $wrap_before;
foreach ( $breadcrumb as $key => $crumb ) {
echo $before;
if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) {
echo '' . esc_html( $crumb[0] ) . '';
} else {
if ( is_product() ) {
unset($crumb);
} else {
echo esc_html( $crumb[0] );
}
}
echo $after;
if ( sizeof( $breadcrumb ) !== $key + 1 ) {
if ( is_product() && sizeof( $breadcrumb ) == $key + 2 ) {
echo '';
} else {
echo $delimiter;
}
}
}
echo $wrap_after;
}

Breadcrumb navigation not showing parent menu on showing current click menu

I am trying to integrate a breadcrumb navigation in an WordPress website, where I would like to display a breadcrumb in the following manner:-
Home >> Parent Menu Name >> Sub Menu Name in Parent Menu
I have tried to implement the following code:-
function dimox_breadcrumbs() {
/* === OPTIONS === */
$text['home'] = 'Home'; // text for the 'Home' link
$text['category'] = 'Archive by Category "%s"'; // text for a category page
$text['search'] = 'Search Results for "%s" Query'; // text for a search results page
$text['tag'] = 'Posts Tagged "%s"'; // text for a tag page
$text['author'] = 'Articles Posted by %s'; // text for an author page
$text['404'] = 'Error 404'; // text for the 404 page
$text['page'] = 'Page %s'; // text 'Page N'
$text['cpage'] = 'Comment Page %s'; // text 'Comment Page N'
$wrap_before = '<div class="breadcrumbs" itemscope itemtype="http://schema.org/BreadcrumbList">'; // the opening wrapper tag
$wrap_after = '</div><!-- .breadcrumbs -->'; // the closing wrapper tag
$sep = '›'; // separator between crumbs
$sep_before = '<span class="sep">'; // tag before separator
$sep_after = '</span>'; // tag after separator
$show_home_link = 1; // 1 - show the 'Home' link, 0 - don't show
$show_on_home = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show
$show_current = 1; // 1 - show current page title, 0 - don't show
$before = '<span class="current">'; // tag before the current crumb
$after = '</span>'; // tag after the current crumb
/* === END OF OPTIONS === */
global $post;
$home_url = home_url('/');
$link_before = '<span itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">';
$link_after = '</span>';
$link_attr = ' itemprop="item"';
$link_in_before = '<span itemprop="name">';
$link_in_after = '</span>';
$link = $link_before . '<a href="%1$s"' . $link_attr . '>' . $link_in_before . '%2$s' . $link_in_after . '</a>' . $link_after;
$frontpage_id = get_option('page_on_front');
$parent_id = ($post) ? $post->post_parent : '';
$sep = ' ' . $sep_before . $sep . $sep_after . ' ';
$home_link = $link_before . '' . $link_in_before . $text['home'] . $link_in_after . '' . $link_after;
if (is_home() || is_front_page()) {
if ($show_on_home) echo $wrap_before . $home_link . $wrap_after;
} else {
echo $wrap_before;
if ($show_home_link) echo $home_link;
if ( is_category() ) {
$cat = get_category(get_query_var('cat'), false);
if ($cat->parent != 0) {
$cats = get_category_parents($cat->parent, TRUE, $sep);
$cats = preg_replace("#^(.+)$sep$#", "$1", $cats);
$cats = preg_replace('#<a([^>]+)>([^<]+)<\/a>#', $link_before . '<a$1' . $link_attr .'>' . $link_in_before . '$2' . $link_in_after .'</a>' . $link_after, $cats);
if ($show_home_link) echo $sep;
echo $cats;
}
if ( get_query_var('paged') ) {
$cat = $cat->cat_ID;
echo $sep . sprintf($link, get_category_link($cat), get_cat_name($cat)) . $sep . $before . sprintf($text['page'], get_query_var('paged')) . $after;
} else {
if ($show_current) echo $sep . $before . sprintf($text['category'], single_cat_title('', false)) . $after;
}
} elseif ( is_search() ) {
if (have_posts()) {
if ($show_home_link && $show_current) echo $sep;
if ($show_current) echo $before . sprintf($text['search'], get_search_query()) . $after;
} else {
if ($show_home_link) echo $sep;
echo $before . sprintf($text['search'], get_search_query()) . $after;
}
} elseif ( is_day() ) {
if ($show_home_link) echo $sep;
echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $sep;
echo sprintf($link, get_month_link(get_the_time('Y'), get_the_time('m')), get_the_time('F'));
if ($show_current) echo $sep . $before . get_the_time('d') . $after;
} elseif ( is_month() ) {
if ($show_home_link) echo $sep;
echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y'));
if ($show_current) echo $sep . $before . get_the_time('F') . $after;
} elseif ( is_year() ) {
if ($show_home_link && $show_current) echo $sep;
if ($show_current) echo $before . get_the_time('Y') . $after;
} elseif ( is_single() && !is_attachment() ) {
if ($show_home_link) echo $sep;
if ( get_post_type() != 'post' ) {
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
printf($link, $home_url . $slug['slug'] . '/', $post_type->labels->singular_name);
if ($show_current) echo $sep . $before . get_the_title() . $after;
} else {
$cat = get_the_category(); $cat = $cat[0];
$cats = get_category_parents($cat, TRUE, $sep);
if (!$show_current || get_query_var('cpage')) $cats = preg_replace("#^(.+)$sep$#", "$1", $cats);
$cats = preg_replace('#<a([^>]+)>([^<]+)<\/a>#', $link_before . '<a$1' . $link_attr .'>' . $link_in_before . '$2' . $link_in_after .'</a>' . $link_after, $cats);
echo $cats;
if ( get_query_var('cpage') ) {
echo $sep . sprintf($link, get_permalink(), get_the_title()) . $sep . $before . sprintf($text['cpage'], get_query_var('cpage')) . $after;
} else {
if ($show_current) echo $before . get_the_title() . $after;
}
}
// custom post type
} elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
$post_type = get_post_type_object(get_post_type());
if ( get_query_var('paged') ) {
echo $sep . sprintf($link, get_post_type_archive_link($post_type->name), $post_type->label) . $sep . $before . sprintf($text['page'], get_query_var('paged')) . $after;
} else {
if ($show_current) echo $sep . $before . $post_type->label . $after;
}
} elseif ( is_attachment() ) {
if ($show_home_link) echo $sep;
$parent = get_post($parent_id);
$cat = get_the_category($parent->ID); $cat = $cat[0];
if ($cat) {
$cats = get_category_parents($cat, TRUE, $sep);
$cats = preg_replace('#<a([^>]+)>([^<]+)<\/a>#', $link_before . '<a$1' . $link_attr .'>' . $link_in_before . '$2' . $link_in_after .'</a>' . $link_after, $cats);
echo $cats;
}
printf($link, get_permalink($parent), $parent->post_title);
if ($show_current) echo $sep . $before . get_the_title() . $after;
} elseif ( is_page() && !$parent_id ) {
if ($show_current) echo $sep . $before . get_the_title() . $after;
} elseif ( is_page() && $parent_id ) {
if ($show_home_link) echo $sep;
if ($parent_id != $frontpage_id) {
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
if ($parent_id != $frontpage_id) {
$breadcrumbs[] = sprintf($link, get_permalink($page->ID), get_the_title($page->ID));
}
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
for ($i = 0; $i < count($breadcrumbs); $i++) {
echo $breadcrumbs[$i];
if ($i != count($breadcrumbs)-1) echo $sep;
}
}
if ($show_current) echo $sep . $before . get_the_title() . $after;
} elseif ( is_tag() ) {
if ( get_query_var('paged') ) {
$tag_id = get_queried_object_id();
$tag = get_tag($tag_id);
echo $sep . sprintf($link, get_tag_link($tag_id), $tag->name) . $sep . $before . sprintf($text['page'], get_query_var('paged')) . $after;
} else {
if ($show_current) echo $sep . $before . sprintf($text['tag'], single_tag_title('', false)) . $after;
}
} elseif ( is_author() ) {
global $author;
$author = get_userdata($author);
if ( get_query_var('paged') ) {
if ($show_home_link) echo $sep;
echo sprintf($link, get_author_posts_url($author->ID), $author->display_name) . $sep . $before . sprintf($text['page'], get_query_var('paged')) . $after;
} else {
if ($show_home_link && $show_current) echo $sep;
if ($show_current) echo $before . sprintf($text['author'], $author->display_name) . $after;
}
} elseif ( is_404() ) {
if ($show_home_link && $show_current) echo $sep;
if ($show_current) echo $before . $text['404'] . $after;
} elseif ( has_post_format() && !is_singular() ) {
if ($show_home_link) echo $sep;
echo get_post_format_string( get_post_format() );
}
echo $wrap_after;
}
}
if (function_exists('dimox_breadcrumbs')) dimox_breadcrumbs();
I am getting the output as followed:-
Home >> Sub Menu Name
Please tell me or correct me what should I update in the code.
Thanks in advance
Your code is working fine, I've tested it on default twentyseventeen WordPress theme.
I guess you just need to create Multi-level Menus properly, or maybe your theme doesn't support that.
When editing the page in the submenu there is a "page attributes" box on the right side. There you can select the parent page for it – which can be a custom link defined in the backend's menu editor. Clearly this affects also the link structure, but then the parent page shows up in the breadcrumb. Maybe this is of help. At least, it was what I was looking for some time.

Wordpress : add permlinks to entire div

Hello, professional coders.
Sorry for my poor English, and I know nothing about code.
I want to add permlink to each post item from blog-layout.php file.
It is related to category page.
I found post loop in there, and want to know how to add permalink.
reference site : http://blog.lgchem.com/category/company-story/
Since I am not a developer, step-by-step instructions would truly be appreciated.
// Start the main loop
while ( have_posts() ): the_post();
// Set the time stamps for timeline month/year check
$alignment_class = '';
if( $blog_layout == 'timeline' ) {
$post_timestamp = get_the_time( 'U' );
$post_month = date( 'n', $post_timestamp );
$post_year = get_the_date( 'o' );
$current_date = get_the_date( 'o-n' );
// Set the correct column class for every post
if( $post_count % 2 ) {
$alignment_class = 'fusion-left-column';
} else {
$alignment_class = 'fusion-right-column';
}
// Set the timeline month label
if ( $prev_post_month != $post_month ||
$prev_post_year != $post_year
) {
if( $post_count > 1 ) {
echo '</div>';
}
echo sprintf( '<h3 class="fusion-timeline-date">%s</h3>', get_the_date( Avada()->settings->get( 'timeline_date_format' ) ) );
echo '<div class="fusion-collapse-month">';
}
}
// Set the has-post-thumbnail if a video is used. This is needed if no featured image is present.
$thumb_class = '';
if ( get_post_meta( get_the_ID(), 'pyre_video', true ) ) {
$thumb_class = ' has-post-thumbnail';
}
$post_classes = sprintf( '%s %s %s post fusion-clearfix', $post_class, $alignment_class, $thumb_class );
ob_start();
post_class( $post_classes );
$post_classes = ob_get_clean();
// post item
echo sprintf( '<div id="post-%s" %s>', get_the_ID(), $post_classes);
// Add an additional wrapper for grid layout border
if ( $blog_layout == 'grid' ) {
echo '<div class="fusion-post-wrapper">';
}
// Get featured images for all but large-alternate layout
if ( Avada()->settings->get( 'featured_images' ) &&
$blog_layout == 'large-alternate'
) {
get_template_part( 'new-slideshow' );
}
// Get the post date and format box for alternate layouts
if ( $blog_layout == 'large-alternate' ||
$blog_layout == 'medium-alternate'
) {
echo '<div class="fusion-date-and-formats">';
/**
* avada_blog_post_date_adn_format hook
*
* #hooked avada_render_blog_post_date - 10 (outputs the HTML for the date box)
* #hooked avada_render_blog_post_format - 15 (outputs the HTML for the post format box)
*/
do_action( 'avada_blog_post_date_and_format' );
echo '</div>';
}
// Get featured images for all but large-alternate layout
if ( Avada()->settings->get( 'featured_images' ) &&
$blog_layout != 'large-alternate'
) {
get_template_part( 'new-slideshow' );
}
// post-content-wrapper only needed for grid and timeline
if ( $blog_layout == 'grid' ||
$blog_layout == 'timeline'
) {
echo '<div class="fusion-post-content-wrapper">';
}
// Add the circles for timeline layout
if ( $blog_layout == 'timeline' ) {
echo '<div class="fusion-timeline-circle"></div>';
echo '<div class="fusion-timeline-arrow"></div>';
}
echo '<div class="fusion-post-content">';
// Render the post title
echo avada_render_post_title( get_the_ID() );
// Render post meta for grid and timeline layouts
if ( $blog_layout == 'grid' ||
$blog_layout == 'timeline'
) {
echo avada_render_post_metadata( 'grid_timeline' );
if ( ( Avada()->settings->get( 'post_meta' ) && ( ! Avada()->settings->get( 'post_meta_author' ) || ! Avada()->settings->get( 'post_meta_date' ) || ! Avada()->settings->get( 'post_meta_cats' ) || ! Avada()->settings->get( 'post_meta_tags' ) || ! Avada()->settings->get( 'post_meta_comments' ) || ! Avada()->settings->get( 'post_meta_read' ) ) ) &&
Avada()->settings->get( 'excerpt_length_blog' ) > 0
) {
echo '<div class="fusion-content-sep"></div>';
}
// Render post meta for alternate layouts
} elseif( $blog_layout == 'large-alternate' ||
$blog_layout == 'medium-alternate'
) {
echo avada_render_post_metadata( 'alternate' );
}
echo '<div class="fusion-post-content-container">';
/**
* avada_blog_post_content hook
*
* #hooked avada_render_blog_post_content - 10 (outputs the post content wrapped with a container)
*/
do_action( 'avada_blog_post_content' );
do_action( 'avada_blog_post_date_and_format' );
echo '</div>';
echo '</div>'; // end post-content
if( $blog_layout == 'medium' ||
$blog_layout == 'medium-alternate'
) {
echo '<div class="fusion-clearfix"></div>';
}
// Render post meta data according to layout
if ( ( Avada()->settings->get( 'post_meta' ) && ( ! Avada()->settings->get( 'post_meta_author' ) || ! Avada()->settings->get( 'post_meta_date' ) || ! Avada()->settings->get( 'post_meta_cats' ) || ! Avada()->settings->get( 'post_meta_tags' ) || ! Avada()->settings->get( 'post_meta_comments' ) || ! Avada()->settings->get( 'post_meta_read' ) ) ) ) {
echo '<div class="fusion-meta-info">';
if ( $blog_layout == 'grid' ||
$blog_layout == 'timeline'
) {
// Render read more for grid/timeline layouts
echo '<div class="fusion-alignleft">';
if ( ! Avada()->settings->get( 'post_meta_read' ) ) {
$link_target = '';
if( fusion_get_page_option( 'link_icon_target', get_the_ID() ) == 'yes' ||
fusion_get_page_option( 'post_links_target', get_the_ID() ) == 'yes' ) {
$link_target = ' target="_blank"';
}
echo sprintf( '<a href="%s" class="fusion-read-more"%s>%s</a>', get_permalink(), $link_target, apply_filters( 'avada_blog_read_more_link', __( 'Read More', 'Avada' ) ) );
}
echo '</div>';
// Render comments for grid/timeline layouts
echo '<div class="fusion-alignright">';
if ( ! Avada()->settings->get( 'post_meta_comments' ) ) {
if( ! post_password_required( get_the_ID() ) ) {
comments_popup_link('<i class="fusion-icon-bubbles"></i> ' . __( '0', 'Avada' ), '<i class="fusion-icon-bubbles"></i> ' . __( '1', 'Avada' ), '<i class="fusion-icon-bubbles"></i> ' . '%' );
} else {
echo sprintf( '<i class="fusion-icon-bubbles"></i> %s', __( 'Protected', 'Avada' ) );
}
}
echo '</div>';
} else {
// Render all meta data for medium and large layouts
if ( $blog_layout == 'large' || $blog_layout == 'medium' ) {
echo avada_render_post_metadata( 'standard' );
}
// Render read more for medium/large and medium/large alternate layouts
echo '<div class="fusion-alignright">';
if ( ! Avada()->settings->get( 'post_meta_read' ) ) {
$link_target = '';
if( fusion_get_page_option( 'link_icon_target', get_the_ID() ) == 'yes' ||
fusion_get_page_option( 'post_links_target', get_the_ID() ) == 'yes' ) {
$link_target = ' target="_blank"';
}
echo sprintf( '<a href="%s" class="fusion-read-more"%s>%s</a>', get_permalink(), $link_target, __( 'Read More', 'Avada' ) );
}
echo '</div>';
}
echo '</div>'; // end meta-info
}
if ( $blog_layout == 'grid' ||
$blog_layout == 'timeline'
) {
echo '</div>' ;
// end post-content-wrapper
}
if ( $blog_layout == 'grid' ) {
echo '</div>'; // end post-wrapper
}
echo '</div>'; // end post
// post item
// Adjust the timestamp settings for next loop
if ( $blog_layout == 'timeline' ) {
$prev_post_timestamp = $post_timestamp;
$prev_post_month = $post_month;
$prev_post_year = $post_year;
$post_count++;
}
endwhile; // end have_posts()
if ( $blog_layout == 'timeline' &&
$post_count > 1
) {
echo '</div>';
}
echo '</div>'; // end posts-container
There's several approaches you could do.
You could either link it to whatever you like in Wordpress CMS backend.
If you want to modify the source code for all the items, you could wrap your div in something like this:
<a href="<?php the_permalink(); ?>">
I would recommend that you have a child theme if you're going to change the source, in that case when your theme (Avada) gets updated, your changes wont disappear.
Read more on permalinks on Wordpress docs:
https://codex.wordpress.org/Function_Reference/the_permalink
https://codex.wordpress.org/Using_Permalinks

How to hide current breadcrumb in Woocommerce

There is breadcrumbs on product page and product title just below them. It's too much for one line and I want to hide current crumb like this:
Home->Catalog->Category->Subcategory->
H1 Product Title
I found in woocommerce/templates/global/breadcrumb.php the part for $crumb. All is a link, but last is a simple text.
foreach ( $breadcrumb as $key => $crumb ) {
echo $before;
if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) {
echo '' . esc_html( $crumb[0] ) . '';
} else {
echo esc_html( $crumb[0] ); // Just replace $crumb here for empty ''
}
echo $after;
if ( sizeof( $breadcrumb ) !== $key + 1 ) {
echo $delimiter;
}
}
Add This CSS in Your Active theme.
.woocommerce-breadcrumb { display:none !important; }
Enjoy.!

Breadcrumbs Subcategory Link is Missing

I dont use plugin for Breadcrumbs. This is ok for me. I checked category parents. Everything is ok. But something wrong
I have a category and sub categories.
Like this :
BCD - Category
xyz -
Sub-Category
Hello -
Post Title.
Code output :
Home Page > BCD > Hello (Where is the sub-category ?)
Sub category is missing.
But if Sub-Category name start with A character For example abc
Code output:
Home Page > BCD > abc > Hello
--
// Breadcrumb
function breadcrumb() {
$delimiter = '';
$name = 'Home'; //text for the 'Home' link
$currentBefore = '<span class="current">';
$currentAfter = '</span>';
echo 'You are here:';
global $post;
$home = get_bloginfo('url');
if(is_home() && get_query_var('paged') == 0)
echo '<span class="home">' . $name . '</span>';
else
echo '<a class="home" href="' . $home . '">' . $name . '</a> '. $delimiter . ' ';
if ( is_category() ) {
global $wp_query;
$cat_obj = $wp_query->get_queried_object();
$thisCat = $cat_obj->term_id;
$thisCat = get_category($thisCat);
$parentCat = get_category($thisCat->parent);
if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
echo $currentBefore;
single_cat_title();
echo $currentAfter;
} elseif ( is_day() ) {
echo '' . get_the_time('Y') . ' ' . $delimiter . ' ';
echo '' . get_the_time('F') . ' ' . $delimiter . ' ';
echo $currentBefore . get_the_time('d') . $currentAfter;
} elseif ( is_month() ) {
echo '' . get_the_time('Y') . ' ' . $delimiter . ' ';
echo $currentBefore . get_the_time('F') . $currentAfter;
} elseif ( is_year() ) {
echo $currentBefore . get_the_time('Y') . $currentAfter;
} elseif ( is_single() ) {
$cat = get_the_category(); $cat = $cat[0];
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
echo $currentBefore;
the_title();
echo $currentAfter;
} elseif ( is_page() && !$post->post_parent ) {
echo $currentBefore;
the_title();
echo $currentAfter;
} elseif ( is_page() && $post->post_parent ) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '' . get_the_title($page->ID) . '';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
echo $currentBefore;
the_title();
echo $currentAfter;
} elseif ( is_search() ) {
echo $currentBefore . 'Search for ' . get_search_query() . $currentAfter;
} elseif ( is_tag() ) {
echo $currentBefore;
single_tag_title();
echo $currentAfter;
} elseif ( is_author() ) {
global $author;
$userdata = get_userdata($author);
echo $currentBefore. $userdata->display_name . $currentAfter;
} elseif ( is_404() ) {
echo $currentBefore . 'Error 404' . $currentAfter;
}
if ( get_query_var('paged') ) {
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
echo $currentBefore . __('Page') . ' ' . get_query_var('paged') . $currentAfter;
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
}
}
I had this issue as well so here is the code I modified to fix this issue...
function wordpress_breadcrumbs() {
$delimiter = '';
$name = 'Home'; //text for the 'Home' link
$currentBefore = '<li>';
$currentAfter = '</li>';
if ( !is_home() && !is_front_page() || is_paged() ) {
echo '<ul id="crumbs">';
global $post;
$home = get_bloginfo('url');
echo '<li>' . $name . '</li> ' . $delimiter . ' ';
if ( is_category() ) {
global $wp_query;
$cat_obj = $wp_query->get_queried_object();
$thisCat = $cat_obj->term_id;
$thisCat = get_category($thisCat);
$parentCat = get_category($thisCat->parent);
if ($thisCat->parent != 0) echo '<li>' .(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' ')) ;
echo $currentBefore ;
echo single_cat_title();
echo $currentAfter;
} elseif ( is_day() ) {
echo '<li>' . get_the_time('Y') . '</li> ' . $delimiter . ' ';
echo '<li>' . get_the_time('F') . '</li> ' . $delimiter . ' ';
echo $currentBefore . get_the_time('d') . $currentAfter;
} elseif ( is_month() ) {
echo '' . get_the_time('Y') . '</li> ' . $delimiter . ' ';
echo $currentBefore . get_the_time('F') . $currentAfter;
} elseif ( is_year() ) {
echo $currentBefore . get_the_time('Y') . $currentAfter;
} elseif ( is_single() ) {
$cat = get_the_category(); $cat = $cat[0];
echo '<li>' .get_category_parents($cat, FALSE, ' <li>' . $delimiter . '');
the_title();
echo $currentAfter;
} elseif ( is_page() && !$post->post_parent ) {
echo $currentBefore;
the_title();
echo $currentAfter;
} elseif ( is_page() && $post->post_parent ) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '' . get_the_title($page->ID) . '';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
echo $currentBefore;
the_title();
echo $currentAfter;
} elseif ( is_search() ) {
echo $currentBefore . 'Search results for '' . get_search_query() . ''' . $currentAfter;
} elseif ( is_tag() ) {
echo $currentBefore . 'Posts tagged '';
single_tag_title();
echo ''' . $currentAfter;
} elseif ( is_author() ) {
global $author;
$userdata = get_userdata($author);
echo $currentBefore . 'Articles posted by ' . $userdata->display_name . $currentAfter;
} elseif ( is_404() ) {
echo $currentBefore . 'Error 404' . $currentAfter;
}
if ( get_query_var('paged') ) {
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
echo __('Page') . ' ' . get_query_var('paged');
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
}
echo '</ul>';
}
}
To call it just put in
<?php if (function_exists('wordpress_breadcrumbs')) wordpress_breadcrumbs(); ?>

Resources