Support » Fixing WordPress » Show total posts number in year/month/day

Viewing 9 replies - 1 through 9 (of 9 total)
  • 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'");

    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.

    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.

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

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

    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.

    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

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

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

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Show total posts number in year/month/day’ is closed to new replies.