


Wouldn’t it be cool to do a site-wide statistics? There are fewer and fewer long-term blogs. Why not give yourself a statistic to see how much effort you have put into this blog. Not only for yourself but also for visitors. wp_count_posts is a function used to count the number of articles in WordPress. It can count all types of posts. of articles (posts) and pages (pages).
Description
wp_count_posts is a function used to count the number of posts in WordPress. It can count all types of posts and pages.
Use
//获取文章数量 $postcount = wp_count_posts(); //获取页面数量 $pagecount = wp_count_posts('page');
Return value
The usage is roughly the same as the above two forms,
The use of this function is mainly on the return value,
The above two forms will return an object,
As follows: The values may be different, but the structure is the same
object(stdClass)#296 (8) { //已发布 ["publish"]=>string(1) "7" //定时发布 ["future"]=>int(0) //草稿 ["draft"]=>int(0) //正在编辑的?(有待考证) ["pending"]=>int(0) //隐私 ["private"]=>int(0) //垃圾箱 ["trash"]=>int(0) //自动草稿 ["auto-draft"]=>int(0) //这个不知道,也没研究 ["inherit"]=>int(0) }
Default usage
The default usage returns the count of published articles. This is an object, and var_dump() can be used in the content to debug the output.
<?php $count_posts = wp_count_posts(); ?>
Get count of published status articles
To get the status type of published articles, you should first call the wp_count_posts() function and then check the "Published" attribute.
<?php $count_posts = wp_count_posts(); $published_posts = $count_posts->publish; ?>
If you are using PHP5 and just want to get the status of an article, you can use the following more convenient method. This code will not run in PHP4, so if you want to maintain backend compatibility, you should choose the above code.
<?php $published_posts = wp_count_posts()->publish; ?>
Draft Count
The method for calculating the number of drafts is the same as the method for obtaining the publication status count.
<?php $count_posts = wp_count_posts(); $draft_posts = $count_posts->draft; ?>
Page Count
The method of calculating the number of page types is the same as calculating the number of articles, and you also need to use the first parameter. Finding the number of pages in a certain state is the same as finding the logs in that state.
<?php $count_pages = wp_count_posts('page'); ?>
Other uses
wp_count_posts() finds the number of any post type in a post state, including attachments and any post types that will be added. This can also be achieved through a plugin or part of the WordPress core team.
Parameters
type
(Character) The type of row in wp_posts, used to check which type corresponds to post_type. Default post.
perm
(character) This parameter can count the private article status into the article status, use 'readable' and require the user to log in. The default is empty string.

wordpress后台乱码的解决办法:1、在wordpress的“wp-admin”文件夹下找到“admin.header.php”文件;2、将“charset”属性值设置为“UTF-8”格式即可恢复正常。

wordpress标签错误的解决办法:1、找到并打开wordpress的“wp-includes”目录下的“class-wp.php”文件;2、修改内容为“$pathinfo = isset( $_SERVER['PATH_INFO'] )?mb_convert_encoding($_SERVER['PATH_INFO'],'utf-8','GBK') : '';”即可。

你下载的WordPress主题提供的keywords和description这两个meta标签一般都做得很差,或者根本就不提供,这样不利于SEO。本文将指导你如何给主页、分类、页面以及文章页添加单独的Description 和 Keywords。

wordpress乱码的解决办法:1、修改“wp-config.php”文件里的“define(’DB_CHARSET’, ‘utf8′);”为“define(’DB_CHARSET’, ”);”;2、把新数据库的编码设置成“latin1_swedish_ci”;3、以uft8的格式导入备份的数据库文件即可。

wordpress进不去的解决办法:1、把地址栏“wp-login.php”后面的参数删掉,然后重新输入密码登录;2、登录FTP,下载“pluggable.php”文件,然后找到“ADMIN_COOKIE_PATH”并将它替换为“SITECOOKIEPATH”即可。

wordpress不是saas。SaaS是一种软件销售模式,它主要针对云端应用软件,而WordPress是一款CMS系统,它主要针对网站构建和管理。虽然WordPress可以作为SaaS提供服务,但它本质上不是一种SaaS应用。

本次PHP中文网整合了相关的视频教程,中文手册,以及相关的精选文章安利给大家,统统免费!!!通过我们分享的视频,可随时随地免费观看教程视频,也不需要迅雷或者百度网盘下载了。

wordpress是2003年发布的;Matt于2003年5月27日宣布推出第一版WordPress,受到了社区的欢迎,它基于b2 Cafelog并有显著改进;WordPress的第一个版本包括全新的管理界面、模板、XHTML 1.1兼容模板、内容编辑器。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools
