WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Plugin: Yoast Breadcrumbs] Obscure Bug in Post Preview (3 posts)

  1. CharlesClarkson
    Member
    Posted 4 years ago #

    Hi,

    A StudioPress user found a bug in the breadcrumbs.php file that comes with our themes. It's very obscure.

    When a post is previewed and has no categories selected it will not return a category and get_the_category() will return an empty array instead of an array of objects.

    In your files, yoast-breadcrumbs.php needs to be changed:

    if (is_single() && $opt['singlecatprefix']) {
        $cats = get_the_category();
        $cat = $cats[0];
        if ($cat->parent != 0) {
            $output .= get_category_parents($cat->term_id, true, " ".$opt['sep']." ");
        } else {
            $output .= '<a href="'.get_category_link($cat->term_id).'">'.$cat->name.'</a> '.$opt['sep'].' ';
        }
    }

    Can be re-written as:

    if (is_single() && $opt['singlecatprefix']) {
        $cats = get_the_category();
        $cat = $cats[0];
        if ( is_object($cat) ) {
            if ($cat->parent != 0) {
                $output .= get_category_parents($cat->term_id, true, " ".$opt['sep']." ");
            } else {
                $output .= '<a href="'.get_category_link($cat->term_id).'">'.$cat->name.'</a> '.$opt['sep'].' ';
            }
        }
    }

    HTH,

    --Charles

  2. Joost de Valk
    Member
    Posted 4 years ago #

    Thanks Charles,

    Updated in the plugin and will update it in the StudioPress themes too!

  3. FelipeTJS
    Member
    Posted 4 years ago #

    Hello, thank you it worked! But it is the home page with the message "Sorry, no posts matched your criteria." and shows the initial posts on the page how to?

Topic Closed

This topic has been closed to new replies.

About this Topic