Last update at :2024-04-02,Edit by888u
Tutorial Preface:
We can usually see the number displayed at the bottom of many common WordPress theme articles.
Someone asked: "How to set the number of articles to be updated on the homepage of the wp theme?" Is there any tutorial?
In this tutorial, a piece of code will make the number of text updates appear on the homepage of your article.
Tutorial Step 1:
Source Code Circle: Add the following code to the functions.php file of the current theme you are using:
// Number of articles updated weekly
function get_week_post_count(){
$date_query = array(
array(
'after'=>'1 week ago'
)
);$args = array(
'post_type' => 'post',
'post_status'=>'publish',
'date_query' => $date_query,
'no_found_rows' => true,
'suppress_filters' => true,
'fields'=>'ids',
'posts_per_page'=>-1
);
$query = new WP_Query( $args );
echo $query->post_count;
}
//Number of articles updated daily
function WeeklyUpdate() {
$today = getdate();
$query = new WP_Query( 'year=' . $today["year"] . '&monthnum=' . $today["mon"] . '&day=' . $today["mday"]);
$postsNumber = $query->found_posts;
echo $postsNumber;
}
PS: Function
get_week_post_count() counts the number of articles updated every week and outputs
WeeklyUpdate() counts the number of articles updated daily and outputs it.
Tutorial Step 2:
Add the above two functions to the desired location on your homepage:
As follows:
This site has a total of: publish;?> articles (including
The WordPress category has count;?> articles),
Updates this week: articles,
Today’s update:
Among them:
//Output the total number of articles on the site
publish;?>
//Query the number of articles in a specific category, for example, I want to check the number of articles in the WordPress category (ID=1)
count;?>
Recommended site searches: Mainland China registration-free space, domain name registration information query, domain name registration query, website registration, Chongqing virtual space, foreign servers, Korean server rental, ftp free space US high defense space, io domain name registration,
p>
发表评论