Make WordPress Core

Changeset 1217


Ignore:
Timestamp:
04/30/2004 06:28:50 PM (21 years ago)
Author:
emc3
Message:

Added 'exclude' parameter to wp_list_cats()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/template-functions-category.php

    r1203 r1217  
    250250    if (!isset($r['feed'])) $r['feed'] = '';
    251251    if (!isset($r['feed_image'])) $r['feed_image'] = '';
    252 
    253     list_cats($r['optionall'], $r['all'], $r['sort_column'], $r['sort_order'], $r['file'],  $r['list'], $r['optiondates'], $r['optioncount'], $r['hide_empty'], $r['use_desc_for_title'], $r['children'], $r['child_of'], $r['categories'], $r['recurse'], $r['feed'], $r['feed_image']);
    254 }
    255 
    256 function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = '', $list = true, $optiondates = 0, $optioncount = 0, $hide_empty = 1, $use_desc_for_title = 1, $children=FALSE, $child_of=0, $categories=0, $recurse=0, $feed = '', $feed_image = '') {
     252    if (!isset($r['exclude'])) $r['exclude'] = '';
     253
     254    list_cats($r['optionall'], $r['all'], $r['sort_column'], $r['sort_order'], $r['file'],  $r['list'], $r['optiondates'], $r['optioncount'], $r['hide_empty'], $r['use_desc_for_title'], $r['children'], $r['child_of'], $r['categories'], $r['recurse'], $r['feed'], $r['feed_image'], $r['exclude']);
     255}
     256
     257function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = '', $list = true, $optiondates = 0, $optioncount = 0, $hide_empty = 1, $use_desc_for_title = 1, $children=FALSE, $child_of=0, $categories=0, $recurse=0, $feed = '', $feed_image = '', $exclude = '') {
    257258    global $tablecategories, $tableposts, $tablepost2cat, $wpdb, $category_posts;
    258259    global $pagenow;
     
    262263        $file = get_settings('home') . '/' . get_settings('blogfilename');
    263264    }
     265
     266    if (!empty($exclude)) {
     267        $exclusions = ''; // initialize for safety
     268        $excats = preg_split('/[\s,]+/',$exclude);
     269        if (count($excats)) {
     270            foreach ($excats as $excat) {
     271                $exclusions .= ' AND cat_ID <> ' . intval($excat) . ' ';
     272            }
     273        }
     274    }
     275
    264276    if (intval($categories)==0){
    265277        $sort_column = 'cat_'.$sort_column;
     
    268280            SELECT cat_ID, cat_name, category_nicename, category_description, category_parent
    269281            FROM $tablecategories
    270             WHERE cat_ID > 0
     282            WHERE cat_ID > 0 $exclusions
    271283            ORDER BY $sort_column $sort_order";
    272284
     
    276288        $cat_counts = $wpdb->get_results("    SELECT cat_ID,
    277289        COUNT($tablepost2cat.post_id) AS cat_count
    278         FROM $tablecategories LEFT JOIN $tablepost2cat ON (cat_ID = category_id)
     290        FROM $tablecategories
     291    LEFT JOIN $tablepost2cat ON (cat_ID = category_id)
    279292        LEFT JOIN $tableposts ON (ID = post_id)
     293    WHERE 1 = 1 $exclusions
    280294        GROUP BY category_id");
    281295        foreach ($cat_counts as $cat_count) {
     
    287301        $cat_dates = $wpdb->get_results("    SELECT cat_ID,
    288302        DAYOFMONTH(MAX(post_date)) AS lastday, MONTH(MAX(post_date)) AS lastmonth
    289         FROM $tablecategories LEFT JOIN $tablepost2cat ON (cat_ID = category_id)
     303        FROM $tablecategories
     304    LEFT JOIN $tablepost2cat ON (cat_ID = category_id)
    290305        LEFT JOIN $tableposts ON (ID = post_id)
     306    WHERE 1 = 1 $exclusions
    291307        GROUP BY category_id");
    292308        foreach ($cat_dates as $cat_date) {
Note: See TracChangeset for help on using the changeset viewer.