WordPress.org

Ready to get started?Download WordPress

Forums

DIsplay new posts count (2 posts)

  1. Yegres
    Member
    Posted 2 years ago #

    How do display total posts count and new posts amount added today? For example:
    Total posts:2000 (+23)?

  2. Yegres
    Member
    Posted 2 years ago #

    Solved.
    Add new widget:

    <h4>Total posts: <strong><?php echo wp_count_posts()->publish; ?></strong> <span style="color: #99cc00;"><span style="color: #000000;">(</span>+<?php   function filter_blog($where = '') {
    //posts in the last 30 days
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-1 days')) . "'";
    return $where;   }
    add_filter('posts_where', 'filter_blog');
    $args=array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'showposts' => -1,
    'caller_get_posts'=> 1
    );
    $my_blog=new WP_Query($args);
    remove_filter('posts_where', 'filter_blog');
    if( $my_blog->have_posts() ) {
    echo count($my_blog->posts) . ' new';
    while ($my_blog->have_posts()) : $my_blog->the_post(); ?>
    <?php     endwhile;   }
    //if ($my_blog) wp_reset_query(); //just in case ?><span style="color: #000000;">)</span></span></h4>

Topic Closed

This topic has been closed to new replies.

About this Topic