警告:count():

时间:2018-11-14 00:18:31

标签: wordpress warnings

朋友们,我在本地主机上运行我的wordpress主题以进行一些更改。它显示以下错误而不显示主导航栏。

错误: 警告:count():参数必须是在284行的C:\ wamp64 \ www \ fiverr \ wp-includes \ post-template.php中实现Countable的数组或对象。调用堆栈#TimeMemoryFunctionLocation 10.0003404144 {main}()。 .. \ index.php:0 20.0004404432require('C:\ wamp64 \ www \ fiverr \ wp-blog-header.php')... \ index.php:17 30.908112387632require_once('C:\ wamp64 \ www \ Fiverr \ wp-includes \ template-loader.php')... \ wp-blog-header.php:19 40.925912455240include('C:\ wamp64 \ www \ fiverr \ wp-content \ themes \ markut \ page.php ')... \ template-loader.php:74 50.925912455240get_header()... \ page.php:11 60.925912455616locate_template()... \ general-template.php:41 70.926112455712load_template()... \ template .php:647 80.926212456184require_once('C:\ wamp64 \ www \ fiverr \ wp-content \ themes \ markut \ header.php')... \ template.php:688 90.927212470664wp_head()... \ header.php :15 100.927212470664do_action()... \ general-template.php:2614 110.927212471040WP_Hook-> do_action()... \ plugin.php:453 120.927212471040WP_Hook-> apply_filters()... \ cl ass-wp-hook.php:310 131.027015883304markut_insert_fb_in_head()... \ class-wp-hook.php:286 141.027015899816the_excerpt()... \ index.php:158 151.027015899816get_the_excerpt()... \ post-template .php:362 161.027115899816apply_filters()... \ post-template.php:397 171.027115900216WP_Hook-> apply_filters()... \ plugin.php:203 181.027115901960wp_trim_excerpt()... \ class-wp-hook.php :288 191.027115901960get_the_content()... \ formatting.php:3308关于我们我们是一个充满活力的团队,Lorem ipsum dolor坐在amet,奉献adipiscing精英,sed do eiusmod“ />

post-template.php的行是: if(post_password_required($ post))// 281 返回get_the_password_form($ post); // 282 if($ page> count($ pages))//如果请求的页面不存在284 $ page = count($ pages); //给他们提供确实存在的编号最高的页面285

2 个答案:

答案 0 :(得分:0)

此错误与WordPress核心错误有关 https://core.trac.wordpress.org/ticket/42814

如果摘录或内容为空,则在循环外调用函数get_the_excerptget_the_content时,通常会发生这种情况。

因此,要自己修复它,您应该找到错误的地方并检查摘录/手动存在的内容。

例如:

if(has_excerpt($post_id)) {
    $meta[] = sprintf('<meta name="description" content="%s">',
        get_the_excerpt($post_id)
    );
}

答案 1 :(得分:0)

这是由于您使用$pages而引起的,而null是因为您不在主循环中。如果尝试计算不可数类型,这将导致php 7.2抛出错误。

您必须使用Wordpress主循环包装代码:

if ( have_posts() ) {
    while ( have_posts() ) { the_post();

        // your code

    }
}