首页 > 解决方案 > 为什么网站仅在类别页面中显示“网站遇到技术问题”错误?

问题描述

每当我从任何已发布的页面或帖子中单击一个类别以转到该类别档案时,它都会给我这个错误,而不是显示该类别的帖子。它仅显示带有错误的站点标题。大多数其他页面工作正常。

我不确定这是否是导致问题的原因,但由于该网站有一个“仅限会员”内容插件,该插件仅向该网站的已登录会员显示一些帖子。此外,Yoast 插件可以选择将帖子的类别设为“主要”类别,并且由于类别按字母顺序排序,例如,如果我们选择了 cat-1 和 cat-2 并将 cat-2一个主要类别,如果 cat-1 按字母顺序排列在 cat-2 之前,它将在网站上显示 cat-1(例如会员和技术,即使我们选择技术作为主要类别,会员也会在网站上显示在原始面包屑上例如)。

我试图做的是隐藏实际的面包屑并按照他们的常见问题解答中的说明显示 Yoast 面包屑。它涉及添加一个小代码,我在实际的面包屑代码之前添加了它并注释了实际的面包屑代码(这只是一个被调用的函数名,但无论如何它都被禁用了)。然后我从 Yoast 的设置面板中启用了面包屑选项(添加了关于添加面包屑的小代码)。

它工作正常并首先显示主要检查的类别,但是当我们进入类别存档页面时(通过从面包屑或菜单下拉菜单中单击它,没有区别),它显示该错误。我禁用了一些插件,还使用了健康检查插件,并在禁用一些插件的情况下对其进行了一些故障排除,但没有积极的结果。

我启用了调试模式以查看错误是什么,这就是它显示的内容:

注意: is_author 调用不正确。条件查询标签在查询运行之前不起作用。在此之前,它们总是返回 false。有关更多信息,请参阅 WordPress 中的调试。(此消息是在版本 3.1.0 中添加的。)在 .../--------/wp-includes/functions.php 的第 4773 行

弃用:与其类同名的方法在 PHP 的未来版本中将不再是构造函数;WPAlchemy_MetaBox 在第 61 行的 .../------/wp-content/plugins/amp-story/vafpress/includes/wpalchemy/MetaBox.php 中有一个已弃用的构造函数

注意:未定义的索引:amp in .../------/wp-content/plugins/amp-story/amp-story.php 在第 50 行

可恢复的致命错误:类 WP_Error 的对象无法在第 2696 行的 .../--------/wp-content/themes/15zine/library/core.php 中转换为字符串

我实际上停用了 AMP 插件,但没有看到任何变化。这可能是另一个问题,但我怀疑 Yoast 插件改变了类别结构的某些内容,但不完全确定。

// Actual breadcrumb function call
<?php cb_breadcrumbs(); ?>
// Yoast breadcrumb code
<?php
if ( function_exists('yoast_breadcrumb') ) {
  yoast_breadcrumb( '<p id="breadcrumbs">','</p>' );
}
?>
// About the breadcrumbs function in core.php file
if ( ! function_exists( 'cb_breadcrumbs' ) ) {

function cb_breadcrumbs() {

    echo cb_get_breadcrumbs();
}

} if ( ! function_exists( 'cb_get_breadcrumbs' ) ) {

function cb_get_breadcrumbs() {

    if ( ot_get_option('cb_breadcrumbs', 'on') == 'off' ) {
        return;
    }

    $cb_breadcrumb = NULL;
    $cb_post_type = get_post_type();
    $cb_cpt = cb_get_custom_post_types();

    if ( is_page() ) {

        global $post;
        if ( $post->post_parent == 0 ) {
            return;
        }
    }


    $cb_breadcrumb = '<div class="cb-breadcrumbs">';
    $cb_icon = '<i class="fa fa-angle-right"></i>';
    $cb_breadcrumb .= '<a href="' . esc_url( home_url() ) . '">' . __("Home", "cubell").'</a>' . $cb_icon;

    if ( is_date() ) {

        if ( is_day() ) {
            $cb_breadcrumb_output = get_the_date( 'F j, Y' );
        } elseif ( is_month() ) {
            $cb_breadcrumb_output = single_month_title( ' ', false );
        } elseif ( is_year() ) {
            $cb_breadcrumb_output = get_query_var( 'year' );
        }

         $cb_breadcrumb .=  '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb">' . $cb_breadcrumb_output . '</div>';
    } elseif ( is_tag() ) {
        $cb_tag_id = get_query_var('tag_id');

        $cb_breadcrumb .= '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="' . get_tag_link($cb_tag_id) . '" title="' . esc_attr( sprintf( __( "View all posts in %s", "cubell" ), single_tag_title( '', FALSE ) ) ) . '" itemprop="url"><span itemprop="title">' . single_tag_title( '', FALSE ) . '</span></a></div>';

    } elseif ( is_category() ) {

        $cb_cat_id = get_query_var('cat');
        $cb_current_category = get_category( $cb_cat_id );

        if ( $cb_current_category->category_parent == '1' ) {

            $cb_breadcrumb .= '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="' . get_category_link( $cb_current_category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s", "cubell" ), $cb_current_category->name ) ) . '" itemprop="url"><span itemprop="title">' . $cb_current_category->name . '</span></a></div>';

        }

        // Line 2696 starts from here  
        // else 
        // {
        //
        //      $cb_breadcrumb .=  '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="' . get_category_link( $cb_current_category->category_parent ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s", "cubell" ), get_the_category_by_ID( $cb_current_category->category_parent ) ) ) . '"><span itemprop="title">' . get_the_category_by_ID( $cb_current_category->category_parent ) . '</span></a></div>' . $cb_icon;
        //      $cb_breadcrumb .= '<div itemprop="child" itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="' . get_category_link( $cb_current_category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s", "cubell" ), $cb_current_category->name ) ) . '" itemprop="url"><span itemprop="title">' . $cb_current_category->name . '</span></a></div>';
        //
        //  }

    } elseif ( function_exists('buddypress') && ( is_buddypress() ) )  {
        global $bp;
        $cb_bp_output = NULL;
        $cb_bp_current_component = bp_current_component();
        $cb_bp_current_action = bp_current_action();

        if ( ( $cb_bp_current_action != 'my-groups' ) && ( $cb_bp_current_component == 'groups' ) ) {

            $cb_bp_group = $bp->groups->current_group;

            if ( ! is_numeric( $cb_bp_group ) ) {
                $cb_bp_group_id = $cb_bp_group->id;
                $cb_bp_group_name = $cb_bp_group->name;
                $cb_bp_group_link = bp_get_group_permalink($cb_bp_group);
                $cb_bp_output = '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="' . trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() ) . '" itemprop="url"><span itemprop="title">' . __('Groups', 'cubell') . '</span></a></div>' . $cb_icon . $cb_bp_group_name;
            } else {
                $cb_bp_output =  __('Groups', 'cubell');
            }

            $cb_breadcrumb .=  $cb_bp_output;
        }

        if ( ( $cb_bp_current_component == 'activity' ) || ( $cb_bp_current_action == 'my-groups' ) || ( $cb_bp_current_action == 'public' ) || ( $cb_bp_current_component == 'settings' ) || ( $cb_bp_current_component == 'forums' ) || ( $cb_bp_current_component == 'friends' ) ) {

            if ( isset( $bp->activity->current_id ) ) {
                $cb_bp_activity = $bp->activity->current_id;
            } else {
                $cb_bp_activity = NULL;
            }

            $cb_activity_title = get_the_title();
            $cb_bp_activity_link = bp_get_members_directory_permalink();
            $cb_bp_output .=  '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="' . esc_url( $cb_bp_activity_link ) . '" itemprop="url"><span itemprop="title">' . __('Members', 'cubell') . '</span></a></div>' . $cb_icon . $cb_activity_title;

            if ( $cb_bp_activity != NULL ) {

                $cb_bp_output .=  __('Members', 'cubell');
            }

            $cb_breadcrumb .=  $cb_bp_output;
        }

        if ( $cb_bp_current_component == 'messages' ) {

            $cb_breadcrumb .=  __('Messages', 'cubell');
        }

        if ( $cb_bp_current_component == 'register' ) {

            $cb_breadcrumb .=  __('Register', 'cubell');
        }

        if ( bp_is_directory() ) {
            $cb_breadcrumb = '<div>';
        }

    } elseif ( ( in_array( $cb_post_type, $cb_cpt ) == true ) || ( $cb_post_type == 'post' ) ) {

        $cb_categories =  get_the_category();

        if ( ! empty ( $cb_categories ) ) {

            if ( $cb_categories[0]->category_parent == '0' ) {

                $cb_breadcrumb .=  '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="' . get_category_link($cb_categories[0]->term_id) . '" title="' . esc_attr( sprintf( __( "View all posts in %s", "cubell" ), $cb_categories[0]->name ) ) . '" itemprop="url"><span itemprop="title">' . $cb_categories[0]->name.'</span></a></div>';

            } else {

                $cb_breadcrumb_output = '<a href="' . get_category_link($cb_categories[0]->category_parent) . '" title="' . esc_attr( sprintf( __( "View all posts in %s", "cubell" ), get_the_category_by_ID($cb_categories[0]->category_parent) ) ) . '" itemprop="url"><span itemprop="title">' . get_the_category_by_ID($cb_categories[0]->category_parent) . '</span></a>' . $cb_icon;

                $cb_breadcrumb_output .= '<a href="' . get_category_link($cb_categories[0]->term_id) . '" title="' . esc_attr( sprintf( __( "View all posts in %s", "cubell" ), $cb_categories[0]->name ) ) . '" itemprop="url"><span itemprop="title">' . $cb_categories[0]->name . '</span></a>';

                $cb_current_cat = get_category($cb_categories[0]->category_parent);

                if ( $cb_current_cat->category_parent != '0' ) {

                    $cb_breadcrumb_output = '<a href="' . get_category_link($cb_current_cat->category_parent) . '" title="' . esc_attr( sprintf( __( "View all posts in %s", "cubell" ), get_the_category_by_ID($cb_current_cat->category_parent) ) ) . '" itemprop="url"><span itemprop="title">' . get_the_category_by_ID($cb_current_cat->category_parent) . '</span></a>' . $cb_icon . $cb_breadcrumb_output;

                    $cb_current_cat = get_category( $cb_current_cat->category_parent );

                    if ( $cb_current_cat->category_parent != '0' ) {

                        $cb_breadcrumb_output = '<a href="' . get_category_link($cb_current_cat->category_parent) . '" title="' . esc_attr( sprintf( __( "View all posts in %s", "cubell" ), get_the_category_by_ID($cb_current_cat->category_parent) ) ) . '" itemprop="url"><span itemprop="title">' . get_the_category_by_ID($cb_current_cat->category_parent) . '</span></a>' . $cb_icon . $cb_breadcrumb_output;

                        $cb_current_cat = get_category( $cb_current_cat->category_parent );

                        if ( $cb_current_cat->category_parent != '0' ) {

                            $cb_breadcrumb_output = '<a href="' . get_category_link($cb_current_cat->category_parent) . '" title="' . esc_attr( sprintf( __( "View all posts in %s", "cubell" ), get_the_category_by_ID($cb_current_cat->category_parent) ) ) . '" itemprop="url"><span itemprop="title">' . get_the_category_by_ID($cb_current_cat->category_parent) . '</span></a>' . $cb_icon . $cb_breadcrumb_output;
                        }
                    }

                }

                $cb_breadcrumb .=  '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb">' . $cb_breadcrumb_output . '</div>';

            }
        }

    } elseif ( is_page() ) {
        $cb_parent_page = get_post( $post->post_parent );

        $cb_parent_page_title = $cb_parent_page->post_title;
        $cb_breadcrumb .=  '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="' . get_permalink( $cb_parent_page->ID ) . '"><span itemprop="title">' . $cb_parent_page_title . '</span></a></div>';
    }


    $cb_breadcrumb .= apply_filters( 'cb_breadcrumbs_output', '' );
    $cb_breadcrumb .= '</div>';


    return $cb_breadcrumb ;
}

}

正如我已经解释并提供了问题的背景一样,我希望看到正确的面包屑(我看到的)并且还可以使类别页面正常工作,但是相反,我只看到网站的标题偏离中心并且错误“该网站遇到了技术难题。” 在它下面。据我检查,大多数其他页面工作正常,只有类别页面有这个问题。甚至管理面板也正常工作。

标签: phpwordpress

解决方案


希望这可以帮助

if ( $cb_current_category->category_parent == '1' ) {

将其更改为

if ( $cb_current_category->category_parent == '0' ) {

从第 2696 行的注释中删除 else。其中一个被附加的东西不是“字符串”,而是一个 WP_Error 对象。

它也可能是 Siteurl 问题。WordPress 数据库中的 Siteurl 选项值可能不包含有效条目

运行以下查询以验证该值确实不正确

SELECT * FROM `wp_options` WHERE option_name = 'siteurl';

您可能会发现一个包含 WP_Error 对象的序列化数组。通过使用您的域的 URL 设置选项值来更正该选项值。

UPDATE wp_options SET option_value = '[YOUR URL]' WHERE option_name = 'siteurl';

可能有恶意软件感染了您的安装。请务必在您的服务器上运行扫描。


推荐阅读