Esempio n. 1
0
function wswwpx_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 = '', $hierarchical = FALSE, $cut_desc = '')
{
    global $wpdb, $category_posts, $wp_query, $myLastCat;
    $myLastCat = $current_cat;
    //	Added for folding functionality... fix for permalink compatibility and modified after further suggestion from Laurence O.
    if (is_category()) {
        $current_cat = $wp_query->get_queried_object_id();
        $all_ancestors = _wswwpx_category_get_ancestor_ids($current_cat);
    } elseif (is_single()) {
        //
        //	Default to zero for all other cases.
        //$current_cat = $myLastCat;
        //	$category->cat_ID = $myLastCat;
        $all_ancestors = _wswwpx_category_get_ancestor_ids($myLastCat);
    } else {
        //
        //	Default to zero for all other cases.
        //$current_cat = $myLastCat;
        //	$category->cat_ID = $myLastCat;
        $all_ancestors[] = 0;
    }
    /*//	Old version... replaced by above for greater compatibility with WP CORE
    		if (isset($_GET['category_name'])) {
    			$all_ancestors = _wswwpx_category_get_ancestor_ids($_GET['category_name']);
    		} else if (isset($_GET['cat'])) {
    			$all_ancestors = _wswwpx_category_get_ancestor_ids($_GET['cat']);
    		} else {
    			//
    			//	Default to zero for all other cases.
    			//
    			$all_ancestors[] = 0;
    		} */
    //	End add
    // Optiondates now works
    if ('' == $file) {
        $file = get_settings('home') . '/';
    }
    $exclusions = '';
    if (!empty($exclude)) {
        $excats = preg_split('/[\\s,]+/', $exclude);
        if (count($excats)) {
            foreach ($excats as $excat) {
                $exclusions .= ' AND cat_ID <> ' . intval($excat) . ' ';
            }
        }
    }
    $exclusions = apply_filters('list_cats_exclusions', $exclusions);
    if (intval($categories) == 0) {
        $sort_column = 'cat_' . $sort_column;
        $query = "\r\n   \t\t\tSELECT cat_ID, cat_name, category_nicename, category_description, category_parent\r\n   \t\t\tFROM {$wpdb->categories}\r\n   \t\t\tWHERE cat_ID > 0 {$exclusions}\r\n   \t\t\tORDER BY {$sort_column} {$sort_order}";
        $categories = $wpdb->get_results($query);
    }
    if (!count($category_posts)) {
        $now = current_time('mysql', 1);
        $cat_counts = $wpdb->get_results("\tSELECT cat_ID,\r\n   \t\tCOUNT({$wpdb->post2cat}.post_id) AS cat_count\r\n   \t\tFROM {$wpdb->categories} \r\n   \t\tINNER JOIN {$wpdb->post2cat} ON (cat_ID = category_id)\r\n   \t\tINNER JOIN {$wpdb->posts} ON (ID = post_id)\r\n   \t\tWHERE post_status = 'publish'\r\n   \t\tAND post_date_gmt < '{$now}' {$exclusions}\r\n   \t\tGROUP BY category_id");
        if (!empty($cat_counts)) {
            foreach ($cat_counts as $cat_count) {
                if (1 != intval($hide_empty) || $cat_count > 0) {
                    $category_posts["{$cat_count->cat_ID}"] = $cat_count->cat_count;
                }
            }
        }
    }
    if ($optiondates) {
        $cat_dates = $wpdb->get_results("\tSELECT category_id,\r\n   \t\tUNIX_TIMESTAMP( MAX(post_date) ) AS ts\r\n   \t\tFROM {$wpdb->posts}, {$wpdb->post2cat}\r\n   \t\tWHERE post_status = 'publish' AND post_id = ID {$exclusions}\r\n   \t\tGROUP BY category_id");
        foreach ($cat_dates as $cat_date) {
            $category_timestamp["{$cat_date->category_id}"] = $cat_date->ts;
        }
    }
    $num_found = 0;
    $thelist = "";
    foreach ($categories as $category) {
        if ((intval($hide_empty) == 0 || isset($category_posts["{$category->cat_ID}"])) && (!$hierarchical || $category->category_parent == $child_of)) {
            $num_found++;
            $link = '<a href="' . get_category_link($category->cat_ID) . '" ';
            if ($use_desc_for_title == 0 || empty($category->category_description)) {
                $link .= 'title="' . sprintf(__("View all posts filed under %s"), wp_specialchars($category->cat_name)) . '"';
            } else {
                //
                //	WSW change to allow for truncated descriptions within link titles.
                //
                //   				$link .= 'title="' . wp_specialchars(apply_filters('category_description',$category->category_description,$category)) . '"';
                $link .= 'title="' . wp_specialchars(wswwpx_category_description($category, $cut_desc, 0)) . '"';
            }
            $link .= '>';
            $link .= apply_filters('list_cats', $category->cat_name, $category) . '</a>';
            if (!empty($feed_image) || !empty($feed)) {
                $link .= ' ';
                if (empty($feed_image)) {
                    $link .= '(';
                }
                $link .= '<a href="' . get_category_rss_link(0, $category->cat_ID, $category->category_nicename) . '"';
                if (!empty($feed)) {
                    $title = ' title="' . $feed . '"';
                    $alt = ' alt="' . $feed . '"';
                    $name = $feed;
                    $link .= $title;
                }
                $link .= '>';
                if (!empty($feed_image)) {
                    $link .= "<img src='{$feed_image}' {$alt}{$title}" . ' />';
                } else {
                    $link .= $name;
                }
                $link .= '</a>';
                if (empty($feed_image)) {
                    $link .= ')';
                }
            }
            if (intval($optioncount) == 1) {
                $link .= ' (' . intval($category_posts["{$category->cat_ID}"]) . ')';
            }
            if ($optiondates) {
                if ($optiondates == 1) {
                    $optiondates = 'Y-m-d';
                }
                $link .= ' ' . gmdate($optiondates, $category_timestamp["{$category->cat_ID}"]);
            }
            if ($list) {
                $css_class = 'page_item';
                /////////////
                //if(!empty ($childs))  $category_posts["$category->cat_ID"]
                if ($current_cat == $category->cat_ID) {
                    $css_class .= ' current_page_item';
                    //	setcookie("wpLastCategory", $current_cat);
                } else {
                    if (in_array($category->cat_ID, $all_ancestors)) {
                        $css_class .= ' current_page_ancestor';
                    }
                }
                //////////////
                $thelist .= "<li class=\"" . $css_class . "\" >{$link}";
                //added class by Georg Leciejewski
            } else {
                $thelist .= "{$link}<br />\n";
            }
            //	Extra 'if' added for folding functionality recursion um children anzuhängen
            if (in_array($category->cat_ID, $all_ancestors)) {
                if ($hierarchical && $children) {
                    $thelist .= wswwpx_list_cats($optionall, $all, $sort_column, $sort_order, $file, $list, $optiondates, $optioncount, $hide_empty, $use_desc_for_title, $hierarchical, $category->cat_ID, $categories, 1, $feed, $feed_image, $exclude, $hierarchical);
                }
            }
            //	End add
            if ($list) {
                $thelist .= "</li>\n";
            }
        }
    }
    if (!$num_found && !$child_of) {
        if ($list) {
            $before = '<li>';
            $after = '</li>';
        }
        echo $before . __("No categories") . $after . "\n";
        return;
    }
    if ($list && $child_of && $num_found && $recurse) {
        $pre = "\n<ul>\n";
        // changed from childeren to class current_page_item georg leciejewski
        $post = "</ul>\n";
    } else {
        $pre = $post = '';
    }
    $thelist = $pre . $thelist . $post;
    if ($recurse) {
        return $thelist;
    }
    echo apply_filters('list_cats', $thelist);
}
Esempio n. 2
0
/**
*@desc the output of the categoriy menu
* @param array $data - holding the switches
* @param int $number - the curretn widget number
*/
function king_cat_output($data, $number)
{
    echo '<!-- Start King Cat ' . $number . ' -->' . "\n";
    echo $data['before_widget'] . "\n";
    echo $data['before_widget_title'] . "\n";
    echo $data['title'] . "\n";
    echo $data['after_widget_title'] . "\n";
    if (function_exists('wswwpx_list_cats') && !empty($options[$number]['foldlist'])) {
        wswwpx_list_cats($data['optionall'] = 0, $data['all'] = 'All', $data['sort_column'], $data['sort_order'], $data['file'], $data['list'], $data['optiondates'], $data['optioncount'], $data['hide_empty'], $data['use_desc_for_title'], $data['children'], $data['child_of'], $data['categories'] = 0, $data['recurse'] = 0, $data['feed'], $data['feed_image'], $data['exclude'], $data['hierarchical']);
    } else {
        list_cats($data['optionall'] = 0, $data['all'] = 'All', $data['sort_column'], $data['sort_order'], $data['file'], $data['list'], $data['optiondates'], $data['optioncount'], $data['hide_empty'], $data['use_desc_for_title'], $data['children'], $data['child_of'], $data['categories'] = 0, $data['recurse'] = 0, $data['feed'], $data['feed_image'], $data['exclude'], $data['hierarchical']);
    }
    echo $data['after_widget'] . "\n";
    echo '<!-- End Cat ' . $number . ' -->' . "\n";
    return;
}