在后台自动把WordPress升级到了3.0,发现博客右侧的"最新评论"失效,一番查找原因,最后解决,大概过程记录如下:

    1.经过查看,发现首页最新评论部分调用的为get_recent_comments函数。

    2.经过查找,发现此函数来源于盆地使用的模板中的functions.php中

    3.经过打印调试日志,发现其中的全局变量$tableposts和$tablecomments失效,从而导致获取最新评论的sql语句失效。

    4.经过查找,发下在WordPress3.0中,上述全局变量已经不再存在,包括上述两个变量在内的有变化的全局变量变化如下:

     $tableposts (use $wpdb->posts)
     $tableusers (use $wpdb->users)
     $tablecategories (use $wpdb->categories)
     $tablepost2cat (use $wpdb->post2cat)(Gone in ver 2.3 $wpdb->terms)
     $tablecomments (use $wpdb->comments)
     $tablelinks (use $wpdb->links)
     $tablelinkcategories (does not exist – all categories are in the main categories table now, and there is not a separate link categories table)
     $tableoptions (use $wpdb->options)
     $tablepostmeta (use $wpdb->postmeta)

    5.替换$tableposts为$wpdb->posts,替换$tablecomments为$wpdb->comments,此问题即解决。

    (完)

标签:
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

6,614次阅读 | penddy on 2010-8-2 8:16 | File Under 软件 | 2 Comments -