WordPress.org

Ready to get started?Download WordPress

Forums

Smart Archives question (1 post)

  1. khaled
    Member
    Posted 9 years ago #

    Ok I'm trying to show the number of posts for a particular month in some brackets after the month (similar in style to the number of comments for any particular post, found on the same page).

    http://www.brokenkode.com/archives

    I'm using the Smart Archives plugin which can be found here:
    http://justinblanton.com/projects/smartarchives/

    This is my modified plugin (yeah took a few brs and deleted some code, but you know what I mean):


    <?php
    /*
    Plugin Name: Smart Archives
    Version: 1.01
    Plugin URI: http://justinblanton.com/projects/smartarchives/
    Description: A simple, clean, and future-proof way to present your archives.
    Author: Justin Blanton
    Author URI: http://justinblanton.com
    */

    function smartArchives(){

    global $tableposts, $PHP_SELF;

    // set the URI of your archives; this might not need to be changed (currently, it's http://yoursite.com/archives/)
    $archive_uri = get_settings('home')."/archives/";
    $now = gmdate('Y-m-d H:i:s'); // get the current GMT date
    $year = date('Y');
    $qy = mysql_query("SELECT distinct year(post_date) as year, post_status FROM $tableposts WHERE post_status='publish' AND post_date <= CURDATE() ORDER BY year desc");

    // loop to create the small archive block with year/month links
    while($years = mysql_fetch_array($qy)) {
    echo('<strong><br/><a href="'.$archive_uri.$years[year].'/">'.$years[year].'</a></strong><br/>'."n");
    $qm = mysql_query("SELECT distinct month(post_date) as month, monthname(post_date) as monthn FROM $tableposts ORDER BY month asc") or die(mysql_error());
    while($date = mysql_fetch_array($qm)) {
    $q = mysql_query("SELECT *, year(post_date) as year, month(post_date) as month FROM $tableposts WHERE year(post_date)='$year' AND month(post_date)='$date[month]' AND post_status='publish' AND post_date <= CURDATE() ORDER BY id desc") or die(mysql_error());
    if(mysql_num_rows($q)) {
    $sm = date("F", StrToTime("$date[month]/01/2001")); // get the shortened month name
    $pd = sprintf("%002s", $date[month]); // pad the month with a zero if needed
    echo('<a href="'.$archive_uri.$year.'/'.$pd.'/">'.$sm.'</a> '."n");
    }
    }
    $year--; // move to previous year
    echo('<br/>'."");
    }

    echo (''."n");

    $year = date('Y'); // reset the year
    $qy = mysql_query("SELECT distinct year(post_date) as year, post_status FROM $tableposts WHERE post_status='publish' AND post_date <= CURDATE() ORDER BY year desc");

    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.