WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Show total posts number in year/month/day (10 posts)

  1. Tunghsiao Liu
    Member
    Posted 7 years ago #

    i searched the wordpress.org and only found a way to show post number by category:
    http://wordpress.org/support/topic/12805

    but, i can't find an answer to my question:

    in http://blog.abc.com/2006/09/25/ it shows:
    ** post(s) written in this day.

    in http://blog.abc.com/2006/09/ it shows:
    ** post(s) written in this month.

    in http://blog.abc.com/2006/ it shows:
    ** post(s) written in this year.

    is it easy to do? Thanks.

  2. Try this. It should hopefully work:

    $post = $posts[0]; // Hack
    if (is_year()) {
    $likedate = 'Y-';
    } elseif (is_month()) {
    $likedate = 'Y-m-';
    } elseif (is_day()) {
    $likedate = 'Y-m-d ';
    }
    $count = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_date LIKE '" . get_the_time($likedate) . "%' AND post_date_gmt < '" . current_time('mysql', TRUE) . "' AND post_status = 'publish'");

  3. Tunghsiao Liu
    Member
    Posted 7 years ago #

    i tried this but got nothing, why?

    <?php $post = $posts[0]; // Hack
    if (is_year()) {
    $likedate = 'Y-';
    } elseif (is_month()) {
    $likedate = 'Y-m-';
    } elseif (is_day()) {
    $likedate = 'Y-m-d ';
    }
    $count = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_date LIKE '" . get_the_time($likedate) . "%' AND post_date_gmt < '" . current_time('mysql', TRUE) . "' AND post_status = 'publish'"); ?> post(s) written in this month.

  4. My code only sets the variable $count. You need to output it:

    <?php echo $count; ?> posts written this month.

    Either that, replace "$count =" with "echo" in my original code and what you have will work.

  5. Ryan Fitzer
    Member
    Posted 7 years ago #

    Should this be in the loop? I gave it a try and both examples printed 0.

  6. Ryan Fitzer
    Member
    Posted 7 years ago #

    Tried the loop with no luck either. Still got 0.

  7. Yeah, it should be after <?php if (have_posts()) : ?>.

    And you could be doing it correctly. I haven't actually tested my code, but I will if you keep getting 0.

  8. Just tried it on the default theme on my local test blog and it works fine.

    Here's what I did as a test: http://wordpress.pastecode.com/5621

  9. Ryan Fitzer
    Member
    Posted 7 years ago #

    Yeah. Tried it on a default install and it worked great. Thanks.

  10. Tunghsiao Liu
    Member
    Posted 7 years ago #

    yeah, i tried it and now it works! great thanks! Viper007Bond, and also thanks for your great Quote Plugin!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.