小工具      在线工具  汉语词典  dos游戏  css  js  c++  java

wordpress评论插件_如何在没有插件的情况下显示WordPress中评论最多的帖子

java,python,php,wordpress,css 额外说明

收录于:15天前

WordPress 评论插件

When we wrote about how to 显示 WordPress 中评论最多的帖子, we highlighted a plugin to make beginner’s life easier. However some of our users asked us if there was a way to display most commented posts without installing a plugin. In this article, we will share a code snippet that you can add to display most commented posts in WordPress without a plugin.

当我们撰写有关如何在 WordPress 中显示评论最多的帖子时 ,我们重点介绍了一个插件,可简化初学者的生活。 但是,我们的一些用户问我们是否有一种无需安装插件即可显示评论最多的帖子的方法。 在本文中,我们将共享一个代码片段,您可以添加该代码片段以显示WordPress中大多数无插件的帖子。

如果您正在学习构建 WordPress 主题并且不想使用插件,这非常有用。

如果您正在学习构建 WordPress 主题并且不想使用插件,这非常有用。

Please note, that this method is not suitable for beginners. If you do not feel confident about adding code, then you should checkout our guide on how to display WordPress 中评论最多的帖子 by using a plugin. If you are looking for a way to display your most popular content, then checkout our list of the best WordPress 的热门帖子插件.

请注意,此方法不适合初学者。 如果您对添加代码不满意,则应查阅我们的指南,以了解如何通过使用插件在 WordPress 中显示评论最多的帖子 。 如果您正在寻找一种显示最受欢迎的内容的方法,请查看最流行的 WordPress 帖子插件列表。

让我们开始吧,首先您需要将以下代码添加到您的主题或子主题的functions.php 文件或特定于站点的插件中。

让我们开始吧,首先您需要将以下代码添加到您的主题或子主题的functions.php 文件或特定于站点的插件中。



function wpb_most_commented_posts() { 
// start output buffering
ob_start();
?>
<ul class="most-commented">
<?php 
// Run WP_Query
// change posts_per_page value to limit the number of posts
$query = new WP_Query('orderby=comment_count&posts_per_page=10'); 

//begin loop
while ($query->have_posts()) : $query->the_post(); ?>

<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> <span class="wpb-comment-count"><?php comments_popup_link('No Comments;', '1 Comment', '% Comments'); ?></span></li>
<?php endwhile; 
// end loop
?>
</ul>
<?php

// Turn off output buffering
 $output = ob_get_clean(); 

//Return output 
return $output; 
}
// Create shortcode
add_shortcode('wpb_most_commented', 'wpb_most_commented_posts'); 

//Enable shortcode execution in text widgets
add_filter('widget_text', 'do_shortcode');

此代码运行数据库查询并按评论计数顺序获取 10 个帖子。我们使用了输出缓冲,以便我们可以使用代码来创建短代码。

此代码运行数据库查询并按评论计数的顺序获取 10 个帖子。我们已经使用了输出缓冲,因此我们可以使用代码创建一个短代码。

The last line enables shortcode execution in text widgets. Now in order to show the results, all you need to do is add [wpb_most_commented] shortcode in a text widget, or in any WordPress post or page.

最后一行启用文本小部件中的短代码执行。 现在,为了显示结果,您需要做的就是在文本小部件或任何WordPress帖子或页面中添加[wpb_most_commented]短代码。

To display post thumbnail next to post titles, you need to add this line just after <li> and post title.

要在帖子标题旁边显示帖子缩略图,您需要在<li>和帖子标题之后添加此行。


<?php the_post_thumbnail(array(40,40)); ?>

数组中使用的值将定义帖子缩略图的自定义大小。您可以调整它以满足您的需要。

数组中使用的值将定义帖子缩略图的自定义大小。您可以调整它以满足您的需要。

To style the output you can use .most-commented and .wpb-comment-count classes in your theme’s stylesheet. You can use this CSS to get started:

要设置输出样式,可以在主题的样式表中使用.wpb-comment-count .most-commented.wpb-comment-count类。 您可以使用以下CSS入门:


.most-commented li { 
border-bottom:1px solid #eee; 
padding-bottom:3px; 
} 
.most-commented li :after { 
clear:both;
} 
.most-commented img { 
padding:3px;
margin:3px;
float:left;
}
.wpb_comment_count a, .wpb_comment_count a:active, .wpb_comment_count a:visited, .wpb_comment_count a:hover { 
color:#FFF;
} 

我们希望这篇文章可以帮助您在 WordPress 中显示最多评论的帖子,而无需安装新插件。请随意尝试代码和 CSS。

我们希望这篇文章可以帮助您在 WordPress 中显示评论最多的帖子,而无需安装新插件。请随意尝试代码和 CSS。

If you liked this article, then subscribe to our YouTube 频道 for WordPress video tutorials. You can also find us on 谷歌+ or 推特.

如果您喜欢这篇文章,请订阅我们的YouTube 频道的WordPress视频教程。 您也可以在谷歌+在推特上找到我们。

翻译自: https://www.wpbeginner.com/wp-themes/how-to-display-most-commented-posts-in-wordpress-without-a-plugin/

WordPress 评论插件

. . .

相关推荐

额外说明

VS Code中将 “ .art “ 文件识别为 “ .html “ 文件

例如: 解决方法: (1) " ctrl+shift+p "打开搜索面板; (2)输入 " open settings (json) ";   (3)在 " settings.json "文件中添加代码: "files.associations": { 

额外说明

UE5——问题——安卓打包设置屏幕方向

Portrait :竖屏 Reverse Portrait :竖屏旋转180度 Sensor Portrait:在设备支持的情况下,根据设备位置传感器,使用纵向或反向纵向 Landscape :横屏 Reverse Landscape :横屏旋转180度

额外说明

【STM32】基础知识 第八课 MDK 工程

【STM32】基础知识 第八课 MDK 工程 准备工作 新建寄存器版本 MDK 工程步骤 新建工程文件夹 添加文件 魔术棒设置 绝对路径和相对路径对比 测试程序 新建 HAL 库版本 MDK 工程 CMSIS HAL 库简介 Drivers Middle

额外说明

简单记录下gorm中存储json

1、定义实体类 package model import ( "database/sql/driver" "encoding/json" "gorm.io/gorm" ) type Profile struct { Email strin

额外说明

可视化学习笔记01

文章目录 一、大数据时代 二、大数据处理流程 三、可视化概述 四、可视化原则 五、可视化工具 (一)数据统计图表化工具 (二)数据结果展示化工具 六、案例演示 任务1、用文字、表格和图表三种方式来表达7次全国人口普查数据 1、文字方式 2、表格方式 3、

额外说明

由浅入深理解java集合(一)——集合框架 Collection、Map

Java 提供了一套完整的集合类(也可以叫做容器类)来管理一组长度可变的对象(也就是集合的元素),其中常见的类型包括 List、Set、Queue 和 Map。从我个人的编程经验来看,List 的实现类 ArrayList 和 Map 的实现类 Hash

额外说明

《实战:如何搭建一个完整的 Vue2.0 项目》- 2、vue.config.js 配置

构建项目时不会自动创建 vue.config.js 文件,需要在根目录下手动创建。插件 @vue/clli-service 会自动加载。直接拷贝如下内容即可。 该文件很丰富,有很多配置项,可自行研究(链接)。这里只列了我的项目中常用的配置。 const

额外说明

Dynamics 365应用程序开发- 4. 使用业务规则设计器定义业务规则

在上一章中,我们看到了如何使用新的Visual Process Designer来使用拖放功能创建业务流程流。在本章中,我们将看到如何使用相同的可视化拖放流程设计器来创建业务规则。 业务规则首次在Dynamics CRM 2013中引入。基本上,业务规则

额外说明

mysql-->判断是否包含

目录 一、说明: 二、涉及/可用函数: 1、INSTR(str,substr) 2、POSITION( substring IN string ) 3、LOCATE (substring; string) 4、正则表达式regexp 建测试表语句 一、说

额外说明

spring boot 动态代理

springboot团队之所以默认的代理模式设置成cglib代理,看看spring的官方团队是怎么解释的 This was changed in 1.4 (see https://github.com/spring-projects/spring-boo

ads via 小工具