wordpress列数布局_如何在WordPress注释布局中添加数字

wordpress列数布局

Earlier on WPBeginner, we showed you how to style your WordPress comments and the comment form. In this article, we will show you how to further customize the comment layout by adding numbers to your WordPress comments.

之前在WPBeginner上,我们向您展示了如何设置WordPress注释注释表单的 样式 。 在本文中,我们将向您展示如何通过在WordPress注释中添加数字来进一步自定义注释布局。

最终结果: (Final results:)

Comments with numbers in WordPress
在WordPress中添加注释编号 (Adding Comment Numbering in WordPress)

First thing you need to do is install and activate Greg’s Threaded Comment numbering plugin. After activating the plugin, go to Settings » Threaded Comment Numbering. Under the Styling Comment Numbers section, select the option: No – I will provide my own number styling. Below that there is another option to Strip the Comment Number Wrapper. Select No on that option as well and save settings.

您需要做的第一件事是安装并激活Greg的Threaded Comment编号插件。 激活插件后,转到“设置”»“主题注释编号” 。 在样式注释编号部分下,选择以下选项: 否-我将提供自己的编号样式 。 在此之下,还有另一个选项可以剥离注释编号包装器 。 还要在该选项上选择“ ”并保存设置。

Configuring threaded comment numbering plugin

Since we are not using the plugin’s stylesheet, we need to define styles in our own stylesheet. We also configured the plugin to wrap comment numbers in a <div class="commentnumber"&> wrapper, so we can style the number using the .commentnumber class. To add custom styles, go to Appearance » Editor and add the following code at the bottom of your theme’s style.css file:

由于我们没有使用插件的样式表,因此我们需要在自己的样式表中定义样式。 我们还配置了插件,以将注释数字包装在<div class="commentnumber"&>包装器中,因此我们可以使用.commentnumber类对数字进行样式设置。 要添加自定义样式,请转到外观»编辑器,然后在主题的style.css文件底部添加以下代码:


.commentlist li .commentnumber {
float:right;
color:#999999;
font-size:3em;
margin:0;
padding:0 .5em .5em 0;
clear:right;
}

.commentlist li li .commentnumber {
font-size:1.7em;
}

.commentlist li li li .commentnumber {
font-size:1.3 em;
}

The plugin we are using uses a callback inside wp_list_comments() function. You can just edit your theme’s comments.php template and replace the existing wp_list_comments with the one provided by the plugin:

我们正在使用的插件在wp_list_comments()函数内部使用了一个回调。 您可以只编辑主题的comments.php模板,并用插件提供的wp_list_comments替换现有的wp_list_comments

<?php wp_list_comments('callback=gtcn_basic_callback'); ?>

For most folks this should work. However for some of you it may end up looking messy at first. You would need to take a few extra steps to fix that. Start out by finding which callback function your theme is using for the comments, and then add the plugin’s callback inside that function.

对于大多数人来说,这应该有效。 但是,对于某些人来说,一开始它可能看起来看起来很凌乱。 您将需要采取一些额外的步骤来解决此问题。 首先找到主题使用的回调函数进行注释,然后在该函数中添加插件的回调。

To find out which function your theme is using as callback, all you have to do is look for wp_list_comments function in comments.php template. For example, in the default WordPress TwentyTwelve theme you would see this:

要找出哪些功能你的主题是利用回调,所有你需要做的就是寻找wp_list_comments在功能上comments.php模板。 例如,在默认的WordPress TwentyTwelve主题中,您将看到以下内容:


<?php wp_list_comments( array( 'callback' => 'twentytwelve_comment', 'style' => 'ol' ) ); ?>

twentytwelve_comment is the callback function you were looking for. Now you need to go to your theme’s functions.php file and look for the comment callback function. Once you find it, you will need to modify this function and add threaded comment numbering to it just before the author name.

twentytwelve_comment是您要查找的回调函数。 现在,您需要转到主题的functions.php文件,并查找注释回调函数。 找到它后,您将需要修改此功能,并在作者姓名之前在其上添加线程注释编号。


<?php 
$comment_number = gtcn_comment_numbering($comment->comment_ID, $args); 
echo $comment_number;
?>

Save your changes and check your comments. Your comments should now have numbers on the right, like this:

保存更改并检查您的评论。 您的评论现在应该在右边带有数字,如下所示:

Comments with numbers in WordPress

We hope this article helped you add numbers to your WordPress comments layout. Would you add numbers to your comments? Let us know by leaving a comment below.

我们希望本文能帮助您在WordPress注释布局中添加数字。 您会在评论中添加数字吗? 让我们在下面留下评论。

翻译自: https://www.wpbeginner.com/wp-themes/how-to-add-numbers-to-your-wordpress-comments-layout/

wordpress列数布局

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值