wordpress显示摘要_如何显示WordPress中的帖子总数

wordpress显示摘要

Do you want to show the total number of posts on your WordPress site? Showing total number of articles may help showcase the consistency of your blog and encourages users to look for more content. In this article, we will show you how to easily display total number of posts in WordPress.

您是否要显示WordPress网站上的帖子总数? 显示文章总数可以帮助显示博客的一致性,并鼓励用户寻找更多内容。 在本文中,我们将向您展示如何轻松显示WordPress中的帖子总数。

Show total number of posts in WordPress
方法1:使用插件显示WordPress中的帖子总数 (Method 1: Show Total Number of Posts in WordPress Using a Plugin)

This method is easier and recommended for all users.

此方法更简单,建议所有用户使用。

First thing you need to do is install and activate the Simple Blog Stats plugin. For more details, see our step by step guide on how to install a WordPress plugin.

您需要做的第一件事是安装并激活Simple Blog Stats插件。 有关更多详细信息,请参阅有关如何安装WordPress插件的分步指南。

Upon activation you need to visit Settings » Simple Blog Stats to configure plugin settings.

激活后,您需要访问设置»简单博客统计信息以配置插件设置。

Simple Blog Stats plugin shows you useful WordPress stats like total number of comments, users, pages and posts. You can easily display these stats using shortcodes anywhere on your WordPress site.

简单的博客统计插件可为您显示有用的WordPress统计信息,例如评论,用户,页面和帖子的总数。 您可以在WordPress网站上的任何位置使用简码轻松显示这些统计信息。

Blog stats shortcodes

Simply copy the [sbs_posts] shortcode and add it to any WordPress post, page, or shortcode enabled sidebar widget.

只需复制[sbs_posts]简码并将其添加到任何启用 WordPress帖子,页面或启用简码的侧栏小部件即可

It will show the total number of published posts on your WordPress site.

它将显示您的WordPress网站上已发布帖子的总数。

number of posts

You can also use [sbs_blog_stats] which will show all blog stats including the total number of posts.

您也可以使用[sbs_blog_stats]显示所有博客统计信息,包括帖子总数。

Blog stats
方法2。手动显示WordPress中的帖子总数 (Method 2. Manually Display Total Number of Posts in WordPress)

This method requires you to add code to your WordPress site. If you haven’t done this before, then take a look at our guide on how to copy and paste code in WordPress.

此方法要求您将代码添加到WordPress网站。 如果您以前没有做过,请查看我们的指南, 了解如何在WordPress中复制和粘贴代码

First you need to add this code to your theme’s functions.php file or a site-specific plugin.

首先,您需要将此代码添加到主题的functions.php文件或特定站点的插件中


function wpb_total_posts() { 
$total = wp_count_posts()->publish;
echo 'Total Posts: ' . $total;
} 

This code simply output the total number of posts whenever the template tag wpb_total_posts is called.

每当调用模板标签wpb_total_posts时,此代码仅输出帖子总数。

Next, you need to add <?php wpb_total_posts(); ?> in your theme files where you want to display total number of posts.

接下来,您需要添加<?php wpb_total_posts(); ?> <?php wpb_total_posts(); ?>在主题文件中要显示帖子总数的位置。

If you don’t want to use the template tag, then you can create and use a shortcode that does exactly the same thing.

如果您不想使用template标记,则可以创建和使用执行完全相同功能的简码。

Copy and paste the following code to your theme’s functions.php file or a site-specific plugin to create a shortcode:

将以下代码复制并粘贴到主题的functions.php文件或特定站点的插件中以创建简码:


function wpb_total_posts() { 
$total = wp_count_posts()->publish;
return $total; 
} 
add_shortcode('total_posts','wpb_total_posts');

Now you can use the shortcode [total_posts] to display total number of posts in any posts, pages, or sidebar widgets.

现在,您可以使用简码[total_posts]显示任何帖子,页面或侧边栏小部件中的帖子总数。

We hope this article helped you learn how to show total number of posts in WordPress. You may also want to see our mega list of most wanted WordPress tips, tricks, and hacks.

我们希望本文能帮助您学习如何显示WordPress中的帖子总数。 您可能还想查看我们的大型列表, 其中包括最想要的WordPress技巧,窍门和技巧

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

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

翻译自: https://www.wpbeginner.com/plugins/how-to-show-total-number-of-posts-in-wordpress/

wordpress显示摘要

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值