Use the Wp_count_posts function to count the number of articles in WordPress, wordpresswpposts_php tutorial

Source: Internet
Author: User
Tags nginx server

Use the Wp_count_posts function in WordPress to count the number of articles, wordpresswpposts


Isn't it cool to do a total station statistic? The long-term blog less and fewer, why not give yourself a statistic, see how much you have worked on this blog, not only to give themselves also to tourists, wp_count_posts is used in WordPress to count the number of articles in the function, You can count all types of articles (post) and Pages (page).

Describe
Wp_count_posts is a function that counts the number of articles in WordPress, and can be used to count all types of articles (post) and Pages (page).

Use

Gets the number of articles $postcount = Wp_count_posts ();//Gets the number of pages $pagecount = wp_count_posts (' page ');

return value
The use of the above is generally the above two forms,
The function is used primarily on the return value,
Both of the above forms return an object,
As follows: May not be the same value, but the structure is the same

Object (StdClass) #296 (8) {//Published ["Publish"]=>string (1) "7"//Timed release ["Future"]=>int (0)//Draft ["Draft"]=>int (0)// Being edited? ["Pending"]=>int (0)//privacy ["Private"]=>int (0)//Trash Box ["Trash"]=>int (0)//Auto Draft ["Auto-draft"]=>int (0) This does not know, nor research ["Inherit"]=>int (0)}

Default usage

The default usage returns the count of published articles. This is an object that can be used to debug the output with Var_dump () in the content.

<?php $count _posts = wp_count_posts ();?>

Get the count of publication status articles

To get the status type of a published article, you should first call the Wp_count_posts () function and then check the "Publish" property.

<?php $count _posts = wp_count_posts ();  $published _posts = $count _posts->publish;?>

If you use PHP5 and only want to get an article status, you can use the following more convenient method. This code does not work in PHP4, so if you want to keep your background compatible, you should choose the code above.

<?php $published _posts = wp_count_posts ()->publish;?>

Draft count

Calculating the draft quantity method is consistent with getting the publication State Count method.

<?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 the calculation article, which also takes advantage of the first parameter. Finding the number of pages in a state is the same as finding a log method in that state.

<?php $count _pages = wp_count_posts (' page ');?>

Other usage

Wp_count_posts () can find the number of any log types in the log state, including attachments and any log types that will be added, or it can be achieved through plug-ins or part of the WordPress core team.

Parameters

Type

(character) wp_posts the type of row to verify which type corresponds to Post_type. Default post.

Perm

(character) This parameter calculates the state of a private article in the article State, using ' readable ' and requiring the user to log in. The default is empty string.

Articles you may be interested in:

    • Analysis of correlation function used in WordPress development for caption Display
    • Analysis of PHP function usage in debugging thumbnail in WordPress
    • configuration resolves the WordPress path in the Nginx server does not automatically add a slash problem
    • The PHP function used in WordPress to get the search form is parsed
    • PHP functions for invoking comment templates and looping out comments in WordPress
    • A detailed description of the use of classification function wp_list_categories in WordPress
    • WordPress restricts non-admin users to comment only once after the article
    • Detailed PHP functions for creating and adding filters in WordPress
    • A detailed description of the use of Wp_title () functions in WordPress development

http://www.bkjia.com/PHPjc/1088778.html www.bkjia.com true http://www.bkjia.com/PHPjc/1088778.html techarticle in WordPress using the Wp_count_posts function to count the number of articles, wordpresswpposts do a total station statistics is not cool? The long-term blog is getting smaller, why not give yourself a statistic, ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.