• Hi,
    I am wanting to display the number of posts for an archive page, in my for a month and for all my searching I have only come across code displays the totals for all the archives you have eg.
    May (10)
    April (17)
    Febuary (2)

    The code is as follows.
    <?php wp_get_archives('type=monthly&amp;show_post_count=1'); ?>

    What I want is some code to display the number of posts for just the current archive page so if I am in Mays page then I would use my code where I want to display the number of posts and it would return X.. eg.

    You are viewing May 2009 archives. There are 10 posts.

    but the code would be something like this
    You are viewing May 2009 archives. There are<?php get_count($theCurrentArchiveMonth); ?> posts.

    Of course my example code is wrong, but that’s what I am trying to achieve. Any pointers would be apreciated. Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Did you ever find a solution for this? I am looking for the same thing.

    The main reason is for tag archives and monthly archive. I would like the top of a tag archive to read” This is the archive of all of the posts tagged with the word wordpress. There are 10 posts with that tag.

    If you are still having issues with this, I can help you offline. Hit me up here: http://blogcraving.com/contact-us/

    Thanks for the help guys. I was able to figure this out last night. Here is my code if this helps anyone else:

    <?php /* If this is a tag archive */ } elseif (is_tag()) { ?>
    <h2 class=”pagetitle”>”<?php single_tag_title(); ?>” Tag Archive</h2>
    <?php
    $count = 0;
    if (have_posts()) : while(have_posts()): the_post(); ?>

    <?php $count++;
    endwhile; endif; ?>
    <?php if ($count == ‘1’) { ?>
    <p>Below is the one article tagged with the term “<?php single_tag_title(); ?>“. </p>
    <?php } else { ?> <p>Below are the <?php echo $count; ?>
    articles tagged with the term “<?php single_tag_title(); ?>“. </p>

    <?php } ?>

    This is in my archive.php theme file. At the top of the page, if this is a tag archive, it displays the page title and then under that it has a sentence. That sentence has two cases. One if there is one article in the archive (to remain grammatically correct) and one case if there are multiple cases. If there are multiple posts in the archive, it displays the number in the sentence.

    Not sure if you are comfortable performing straight-up database queries like this, but this works:

    } elseif (is_month()) {
    	// Custom: Get Total Publications by Month
    	$year_month = get_the_time('Y-m');
    	$numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type='post' AND post_date LIKE '$year_month%'");
    	$numposts = number_format($numposts);
    	echo $numposts; ?>

    I used a similar function to do archive pages per author also.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Number of posts for an archive page’ is closed to new replies.