-
-
Save Dimox/5654092 to your computer and use it in GitHub Desktop.
Hi, I have this error :
Trying to get property of non-object
for this line :
$parent_id = $parent_id_2 = $post->post_parent;
in search results page when the query not found
You may fix the empty search results error (Notice: Tryin to get property of non-object...) by replacing line 40 ($parent_id = $post->post_parent) by the following code:
if (have_posts()) {
$parent_id = $post->post_parent;
}
Please add support for Woo Commerce & BBPress.
Thanks
When displaying a post has no category set up will show the error.
Notice: undefined offset:0 on $cat = get_the_category(); $cat = $cat[0];
Catchable fatal error: Object of class WP_Error could not be converted to string in $cats = preg_replace('#<a([^>]+)>([^<]+)<\/a>#', $link_before . '<a$1' . $link_attr .'>' . $link_in_before . '$2' . $link_in_after .'</a>' . $link_after, $cats);
It happened to me also. Please help to fix the error when the post has no category.
I had a problem trying to condition this:
-- $thisCat = get_category(get_query_var ('cat'), false); --
-- $thisCat->parent != 0 --
The solution for me:
global $wp_query;
$thisCat = $wp_query->queried_object;
After getting err (Notice: Tryin to get property of non-object...)
changed
$parent_id = $post->post_parent;
to this
$thisPostID = get_the_ID();
$parent_id = wp_get_post_parent_id( $thisPostID );
Can any one tell me I don't want breadcrumb links, it will only text, how to remove the anchor tag from this code
Yeah, on line 101 and 125 there's an error if post is not assigned to any category (there are some cases):
This
$cat = get_the_category(); $cat = $cat[0];
should be replaced with this (after line 101, for example):
$cat = get_the_category();
$cat = isset( $cat ) ? $cat[0] : '';
if( $cat ) {
$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;
}
}else{
if ($showCurrent == 1) {
$breadcrumb_html .= $before . esc_html( strip_tags( get_the_title() ) ) . $after;
}
}
Apply the same logic on line 125 (line number will change after line 101 fix)
Maybe can improve this code for custom taxonomy?
I'm using this function to added custom taxonomy on breadcrumb in conditional is_tax(), but i'm don't understand much about php, so is only a suggest :)
function get_taxonomy_parents( $id, $taxonomy = 'category', $link = false, $separator = '/', $nicename = false, $visited = array() ) {
$chain = '';
$parent = get_term( $id, $taxonomy );
if ( is_wp_error( $parent ) )
return $parent;
if ( $nicename )
$name = $parent->slug;
else
$name = $parent->name;
if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
$visited[] = $parent->parent;
$chain .= get_taxonomy_parents( $parent->parent, $taxonomy, $link, $separator, $nicename, $visited );
}
if ( $link )
$chain .= '<a href="' . esc_url( get_term_link( $parent,$taxonomy ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $parent->name ) ) . '">'.$name.'</a>' . $separator;
else
$chain .= $name.$separator;
return $chain;
}
thank you!
Please fix missing field "id" in Google Search Console. Thank you.
Hello!
Google today started issuing a warning data-vocabulary.org schema deprecated
From April 2020 the current markup won't be supported anymore and Google won't display rich results unless we migrate to a different markup in this code.
@Dimox can you please look into this and let us know if you feel like updating it? Here's detailed info on the issue and example of the new markup: https://www.spyloadedng.com/webmasters-board/breadcrumbs-issue-how-to-fix-data-vocabulary-schema-deprecated/
The alternative seems to be using Yoast SEO's breadcrumbs from their new version.
About Google data vocabulary problem, using last version of the code solved it for me :)
@webarter, I'm not using data-vocabulary.
A custom WordPress nav walker class to implement the Bootstrap 4 breadcrumbs style in a custom theme using the WordPress. Google schema validation is Ok.
wp_breadcrumbs.php
чтобы работало в категориях woocommerce
elseif (is_product_category()) {
$parents = get_ancestors(get_query_var('cat'), 'category');
foreach (array_reverse($parents) as $cat) {
$position += 1;
if ($position > 1) echo $sep;
echo sprintf($link, get_category_link($cat), get_cat_name($cat), $position);
}
if (get_query_var('paged')) {
$position += 1;
$cat = get_query_var('cat');
echo $sep . sprintf($link, get_category_link($cat), get_cat_name($cat), $position);
echo $sep . $before . sprintf($text['page'], get_query_var('paged')) . $after;
} else {
if ($show_current) {
if ($position >= 1) echo $sep;
echo $before . sprintf($text['category'], single_cat_title('', false)) . $after;
} elseif ($show_last_sep) echo $sep;
}
}
чтобы работало в категориях woocommerce
elseif (is_product_category()) { $parents = get_ancestors(get_query_var('cat'), 'category'); foreach (array_reverse($parents) as $cat) { $position += 1; if ($position > 1) echo $sep; echo sprintf($link, get_category_link($cat), get_cat_name($cat), $position); } if (get_query_var('paged')) { $position += 1; $cat = get_query_var('cat'); echo $sep . sprintf($link, get_category_link($cat), get_cat_name($cat), $position); echo $sep . $before . sprintf($text['page'], get_query_var('paged')) . $after; } else { if ($show_current) { if ($position >= 1) echo $sep; echo $before . sprintf($text['category'], single_cat_title('', false)) . $after; } elseif ($show_last_sep) echo $sep; } }
не совсем корректно работает,
Главная->Категория, или Главная->Подкатегория.
Каталог с категориями пропускает + категорию пропускает
Hey nice work!
Can I use this in a commercial product?
Thanks