评论楼层 php,wordpress评论楼层实现方法-支持评论分页

支持评论分页的wordpress评论楼层实现方法。如果你的wordpress开启了评论镶嵌,并且评论比较多情况下就会显的非常乱,而给wordpress增加评论楼层显示,就可以在一定程度上解决评论显示过乱的问题。

实现支持评论分页的楼层显示方法的前提条件:

1. 要在 WordPress 后台开启嵌套评论,2. 所用主题支持嵌套(目前的主题基本都支持吧)

把下面的代码扔function.php里面,不过要注意的是其中的mytheme_comment 回调函数,要与comments.php的相应函数相对应。

开始添加楼层计数参数 $commentcount 等代码,具体看代码中的注释,

function mytheme_comment($comment, $args, $depth){

$GLOBALS[‘comment’] = $comment;

//主评论计数器初始化 begin – by zwwooooo

global $commentcount;

if(!$commentcount) { //初始化楼层计数器

$page = get_query_var(‘cpage’)-1;

$cpp=get_option(‘comments_per_page’);//获取每页评论数

$commentcount = $cpp * $page;

}

//主评论计数器初始化 end – by zwwooooo

?>

id="li-comment-<?php comment_ID() ?>">

<?php echo get_avatar($comment,$size=’48’,$default='’ ); ?>

<?php printf(__(‘%s says:’), get_comment_author_link()) ?>

<?php if ($comment->comment_approved == ‘0’) : ?>

<?php comment_reply_link(array_merge( $args, array(‘depth’ => $depth, ‘max_depth’ => $args[‘max_depth’]))) ?>

<?php if(!$parent_id = $comment->comment_parent) {printf(‘#%1$s’, ++$commentcount);} ?>

需要用到的css样式

ol.commentlist li div.floor{position:absolute;top:0;right:0;}

上面的代码可以实现正序评论楼层显示,下面的代码则可以实现倒序评论楼层显示,前提条件除了上面的两点外还得需要设置WP嵌套评论排序为“由新到旧”

function mytheme_comment($comment, $args, $depth){

$GLOBALS[‘comment’] = $comment;

/* 主评论计数器 by zwwooooo */

global $commentcount,$wpdb, $post;

if(!$commentcount) { //初始化楼层计数器

$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = $post->ID AND comment_type = ” AND comment_approved = ‘1’ AND !comment_parent");

$cnt = count($comments);//获取主评论总数量

$page = get_query_var(‘cpage’);//获取当前评论列表页码

$cpp=get_option(‘comments_per_page’);//获取每页评论显示数量

if (ceil($cnt / $cpp) == 1 || ($page > 1 && $page  == ceil($cnt / $cpp))) {

$commentcount = $cnt + 1;//如果评论只有1页或者是最后一页,初始值为主评论总数

} else {

$commentcount = $cpp * $page + 1;

}

}

/* 主评论计数器 end */

?>

id="li-comment-<?php comment_ID() ?>">

<?php echo get_avatar($comment,$size=’48’,$default='’ ); ?>

<?php printf(__(‘%s says:’), get_comment_author_link()) ?>

<?php if ($comment->comment_approved == ‘0’) : ?>

<?php comment_reply_link(array_merge( $args, array(‘depth’ => $depth, ‘max_depth’ => $args[‘max_depth’]))) ?>

<?php if(!$parent_id = $comment->comment_parent) {printf(‘#%1$s’, –$commentcount);} ?>

显示楼层号的 .floor 参考下面的 css

ol.commentlist li div.floor{position:absolute;top:0;right:0;}

代码来自zwwooooo

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: 要导出WordPress评论,你可以使用WordPress的导出功能。首先,登录到你的WordPress后台,然后导航到“工具”>“导出”。在导出页面中,你可以选择导出的内容类型,包括文章、页面、媒体和评论。选择“评论”并点击“下载导出文件”按钮,WordPress将生成一个XML文件,其中包含了你的所有评论。你可以将这个文件保存到你的计算机上,以备将来使用或导入到其他平台。\[1\] #### 引用[.reference_title] - *1* [批量导出WordPress文章为MD文件](https://blog.csdn.net/qq_45783700/article/details/128685589)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [教大家用WordPress导出全静态化网站,需要怎么操作?](https://blog.csdn.net/weixin_32348697/article/details/118014432)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [如何批量导出 WordPress 的文章?](https://blog.csdn.net/weixin_36338224/article/details/121779665)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值