Make WordPress Core


Ignore:
Timestamp:
07/19/2003 10:55:18 PM (23 years ago)
Author:
mikelittle
Message:

Added last date, post count, and hide empty mods to list_cats.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/b2-include/b2template.functions.php

    r253 r259  
    861861
    862862// out of the b2 loop
    863 function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = 'blah', $list = true) {
    864     global $tablecategories, $querycount, $wpdb;
     863function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc',
     864                   $file = 'blah', $list = true, $optiondates = 0, $optioncount = 0, $hide_empty = 1) {
     865    global $tablecategories, $tableposts, $querycount, $wpdb;
    865866    global $pagenow;
    866867    global $querystring_start, $querystring_equal, $querystring_separator;
    867     $file = ($file == 'blah') ? $pagenow : $file;
     868    if (($file == 'blah') || ($file == '')) {
     869        $file = $pagenow;
     870    }
    868871    $sort_column = 'cat_'.$sort_column;
    869     $categories = $wpdb->get_results("SELECT * FROM $tablecategories WHERE cat_ID > 0 ORDER BY $sort_column $sort_order");
     872
     873    $query  = " SELECT cat_ID, cat_name,";
     874    $query .= "  COUNT($tableposts.ID) AS cat_count,";
     875    $query .= "  DAYOFMONTH(MAX(post_date)) AS lastday, MONTH(MAX(post_date)) AS lastmonth";
     876    $query .= " FROM $tablecategories LEFT JOIN $tableposts ON cat_ID = post_category";
     877    $query .= " WHERE cat_ID > 0 ";
     878    $query .= " GROUP BY post_category ";
     879    if (intval($hide_empty) == 1) {
     880        $query .= " HAVING cat_count > 0";
     881    }
     882    $query .= " ORDER BY $sort_column $sort_order, post_date DESC";
     883
     884    $categories = $wpdb->get_results($query);
    870885    ++$querycount;
    871886    if (intval($optionall) == 1) {
    872887        $all = apply_filters('list_cats', $all);
    873         if ($list) echo "\n\t<li><a href=\"".$file.$querystring_start.'cat'.$querystring_equal.'all">'.$all."</a></li>";
    874         else echo "\t<a href=\"".$file.$querystring_start.'cat'.$querystring_equal.'all">'.$all."</a><br />\n";
     888        $link = "<a href=\"".$file.$querystring_start.'cat'.$querystring_equal.'all">'.$all."</a>";
     889        if ($list) echo "\n\t<li>$link</li>";
     890        else echo "\t$link<br />\n";
    875891    }
    876892    foreach ($categories as $category) {
    877893        $cat_name = apply_filters('list_cats', $category->cat_name);
     894        $link = "<a href=\"".$file.$querystring_start.'cat'.$querystring_equal.$category->cat_ID.'">';
     895        $link .= stripslashes($cat_name)."</a>";
     896        if (intval($optioncount) == 1) {
     897            $link .= "&nbsp;&nbsp;(".$category->cat_count.")";
     898        }
     899        if (intval($optiondates) == 1) {
     900            $link .= "&nbsp;&nbsp;".$category->lastday."/".$category->lastmonth."";
     901        }
     902        $link .= "</a>";
    878903        if ($list) {
    879             echo "\n\t<li><a href=\"".$file.$querystring_start.'cat'.$querystring_equal.$category->cat_ID.'">';
    880             echo stripslashes($cat_name)."</a></li>";
     904            echo "\n\t<li>$link</li>";
    881905        } else {
    882             echo "\t<a href=\"".$file.$querystring_start.'cat'.$querystring_equal.$category->cat_ID.'">';
    883             echo stripslashes($cat_name)."</a><br />\n";
     906            echo "\t$link<br />\n";
    884907        }
    885908    }
Note: See TracChangeset for help on using the changeset viewer.