解决Notice: Undefined index: widget_id in

[存档,分享]

WordPress报错内容: Notice: Undefined index: widget_id in ..\wp-includes\default-widgets.php on line 528

错误触发条件:(本问题多为在提交主题前的调试中遇到)

开启 wp-config.php 中的

define('WP_DEBUG', true);

sidebar.php 或者任意地方调用 the_widget(); 且没有赋予 widget_id 参数就会警告。

这真的是一个小问题,本来根本不会出这个警告的,谁叫WordPress the_widget官方文档  里不会提到触发Notice 的错误呢,搜索到另一个老外调试主题也遇到了这个问题 here 。而且网上没有解决办法,于是我看了 default-widgets.php 的参数,立马石化,发现原来文档参数写的不全。

解决方法:

调用 the_widget 时务必将参数加全,否则尽管不影响主题正常使用,但是提交带有警告的主题给WordPress官方是不可行的。

<?php the_widget('WP_Widget_Recent_Posts', 'number=5&title=21212', 'before_title=<h3 class="widget_title">&after_title =</h3>&widget_id=1234'); ?>
<?php the_widget('WP_Widget_Recent_Comments', 'number=5&title=21212', 'before_title=<h3 class="widget_title">&after_title =</h3>&widget_id=1235'); ?>

就是这个 &widget_id=1234 缺失导致的问题的出现。

版权所有© HzlzH | 本文采用 BY-NC-SA 进行授权
转载需注明 转自: 《解决Notice: Undefined index: widget_id in

相关文章

{ Leave a Reply ? }

  1. zwwooooo China Mozilla Firefox Windows

    沙发!嘿嘿!

  2. zwwooooo China Mozilla Firefox Windows

    官方文档感觉有些很偷懒,主题审核又要高要求有不提供完整的函数说明给主题作者!

  3. 安吉农家乐 China Google Chrome Windows

    好文,我喜欢,我留言

  4. IM路人 China Maxthon Windows

    注册侧边栏模块??

  5. 王尚 China Internet Explorer Windows

    呵呵,我也在研究wordpress

  6. 王尚 China Internet Explorer Windows

    好有技术含量的文章啊,,,呵呵,,没太看懂啊。。

  7. mopvhs China Mozilla Firefox Windows

    收藏~~~

  8. 三棵树人 China Mozilla Firefox Windows

    放假啦~来看看你咯!

  9. WayJam China Maxthon Windows

    常调试是个好习惯,

  10. 识字 China Google Chrome Windows

    很感谢博主的博客能让我留言,谢谢

  11. Neeke China Google Chrome Windows

    :roll: 楼上这个AD怎么没被拦截?

  12. 小邪 China Google Chrome Windows

    官方文档感觉不给力,经常得直接翻代码 ~ ╮(╯▽╰)╭

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

:wink: :twisted: :roll: :oops: :mrgreen: :lol: :idea: :evil: :cry: :arrow: :?: :-| :-x :-o :-P :-D :-? :) :( :!: 8-O 8)