Deprecated: WP_Widget 类在 specs_widget_ad 中的调用构造方法自 4.3.0 版本起以弃用!请使用 __construct() 代替。 in /virtual/blogxc/public_html/wp-includes/functions.php on line 5473

Deprecated: WP_Widget 类在 specs_recommend 中的调用构造方法自 4.3.0 版本起以弃用!请使用 __construct() 代替。 in /virtual/blogxc/public_html/wp-includes/functions.php on line 5473

Deprecated: WP_Widget 类在 specs_tj 中的调用构造方法自 4.3.0 版本起以弃用!请使用 __construct() 代替。 in /virtual/blogxc/public_html/wp-includes/functions.php on line 5473
修改wordpress最新评论不显示博主评论和显示评论内容 | 手机小菜的博客

首页 » WordPress教程 » 正文

修改wordpress最新评论不显示博主评论和显示评论内容

还有一天就考试了,复习啊
最近小菜这评论多了不少,秉着留一条言就回复一下的原则,小菜积极的回复,就造成了变侧栏上的最新评论里显示的很多都是小菜的,看起来不太好看,于是小菜百度了一下,果然就有了方法。
以下是修改方法:

最新评论不显示博主评论:
在wp-includes文件夹里找到default-widgets.php文件进行编辑
搜索找到如下代码

$comments = get_comments( apply_filters( 'widget_comments_args', array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish' ) ) );

加上

, 'user_id' => 0

即改为

$comments = get_comments( apply_filters( 'widget_comments_args', array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'user_id' => 0 ) ) );

即可不显博主评论
如果还想不显示pingback和trackback类留言
在后面加上
[php], ‘type’ => ‘comment'[/php]
即改为[php]$comments = get_comments( apply_filters( ‘widget_comments_args’, array( ‘number’ => $number, ‘status’ => ‘approve’, ‘post_status’ => ‘publish’, ‘user_id’ => 0, ‘type’ => ‘comment’ ) ) );[/php]
就是不显示博主评论+不显示pingback和trackback类留言

让最新评论中直接显示评论内容:
同样是修改default-widgets.php文件
搜索”recentcomments”,找到如下代码
[php]
if ( $comments ) {
foreach ( (array) $comments as $comment) {
$output .= ‘<li class=”recentcomments”>’ . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x(‘%1$s on %2$s’, ‘widgets’), get_comment_author_link(), ‘<a href=”‘ . esc_url( get_comment_link($comment->comment_ID) ) . ‘”>’ . get_the_title($comment->comment_post_ID) . ‘</a>’) . ‘</li>’;
}
[/php]
步骤一:
先把(_x(‘%1$s on %2$s’, ‘widgets’)里面的“on”改成冒号“:”,这是显示样式,你想改成别的也可以。

步骤二:
方法一:
将上面代码中的
[php]get_the_title($comment->comment_post_ID)[/php]
修改为
[php]strip_tags( $comment->comment_content)[/php]
这样会将所有的评论内容显示出来

方法二:
如果你想限制评论字数,可以把
[php]get_the_title($comment->comment_post_ID)[/php]
改为
[php]mb_strimwidth(strip_tags($comment->comment_content),0,60, ……)[/php]
数字60是限制显示评论的字符数,可自行修改,一个汉字占两个字符, ……即是评论字数多于限制的字数时显示的小尾巴,也可自行修改。

好了修改结束。
注意以上方法都只有在你的主题是使用了wordpress自带的近期评论小工具时才有效。

以上代码来自于互联网,由小菜整理。由于网上搜索出来的文章内容大致相同,便未写出来源。


Deprecated: 函数 link_pages 自版本 2.1.0 起已弃用!请使用 wp_link_pages() 替代。 in /virtual/blogxc/public_html/wp-includes/functions.php on line 5380

本文共 22 个回复


  • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

    Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
    贵阳信用卡套现 2016/03/11 12:11

    北京信用卡套现成都信用卡套现,福州信用卡套现,广州信用卡套现。贵阳信用卡套现,哈尔滨信用卡套现,海口信用卡套现,杭州信用卡套现,合肥信用卡套现。惠州信用卡套现,南昌信用卡套现,西安信用卡套现,南京信用卡套现,厦门信用卡套现,南宁信用卡套现,上海信用卡套现,深圳信用卡套现,苏州信用卡套现,天津信用卡套现。武汉信用卡套现,长春信用卡套现,郑州信用卡套现,成都开发票,大连开发票,东莞开发票,佛山开发票,福州开发票,灰色词百度排名.


  • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

    Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
    163邮件列表 2016/03/11 09:33

    “你的是你的,我的是我的。”是凡人说的话;“我的就是你的,你的就是我的。”是无知者说的话;“我的是你的,你的还是你的。”是圣人说的话;“我的是我的,你的也是我的。”也是圣人说的话。


  • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

    Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
    除尘设备市场 2014/01/18 15:51

    新的一年,祝福博主新年快乐!


    • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

      Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
      小菜 博主 2014/01/23 10:18

      @ 除尘设备市场 不好意思哈,最近没时间上网,没看到 谢谢,你也同乐


  • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

    Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
    电石产业研究 2014/01/09 15:22

    传递正能量,支持一下博主


  • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

    Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
    pang 2014/01/09 11:30

    来看看小菜·


  • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

    Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
    馒头饭MADfan 2014/01/07 23:02

    学习了~~~


  • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

    Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
    晨风 2014/01/03 13:59

    牛逼。支持下


    • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

      Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
      小菜 博主 2014/01/03 17:03

      @ 晨风 谢谢支持,这代码不是我弄出来的


  • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

    Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
    博客网址之家 2014/01/03 09:43

    支持博主


    • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

      Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
      小菜 博主 2014/01/03 11:14

      @ 博客网址之家 谢谢支持


  • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

    Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
    NameDomain 2014/01/03 08:32

    是不是每次升级都要改。。。


    • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

      Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
      小菜 博主 2014/01/03 11:13

      @ NameDomain 恩,修改wordpress的原文件基本都是这个样


      • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

        Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
        NameDomain 2014/01/03 17:16

        @ 小菜 还是多说方便


  • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

    Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
    爱浮夸 2014/01/02 22:30

    侧边栏显示是有点怪怪的。


    • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

      Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
      小菜 博主 2014/01/03 11:12

      @ 爱浮夸 那里怪,可以详细说下吗,我好改


  • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

    Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
    无纯洁 2014/01/02 19:10

    学习了。。


  • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

    Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
    小青年 2014/01/02 17:10

    支持下


  • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

    Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
    Youth.霖 2014/01/01 21:28

    评论提交后有wanning


    • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

      Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
      小菜 博主 2014/01/01 21:49

      @ Youth.霖 warning?我开始改主题,网速有点问题,代码保存时丢失了部分,就出问题了,现在问题已解决


  • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

    Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
    Youth.霖 2014/01/01 21:27

    哈哈,我就是这种方法~


    • Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 937

      Notice: Undefined variable: comment_ID in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/functions.php on line 938
      小菜 博主 2014/01/01 21:49

      @ Youth.霖 恩恩,网上都是这方法


Notice: Undefined variable: aria_req in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/comments.php on line 61

Notice: Undefined variable: aria_req in /virtual/blogxc/public_html/wp-content/themes/9IPHP-master2021/comments.php on line 69

发表评论