[wp-hackers] wp_list_categories()
Daiv Mowbray
daiv at daivmowbray.com
Fri Jan 2 11:38:33 GMT 2009
Sorry about the Gaaack,
and yes make_def_list is the entry function.
This code is inside of a multiple widget, ie options are numbered.
In my initial function which does the DB query I first get options:
$options = array();
$options = get_option('My_widget_options');
extract($options[$number]);
Then I go through the exclusions and ordering,
if ($catSort=='catName') {
$catSortColumn="ORDER BY $wpdb->terms.name";
etc.
Then I construct the query based on order type options.
$catquery = "SELECT $wpdb->term_taxonomy.count as 'count',
$wpdb->terms.term_id, $wpdb->terms.name, $wpdb->terms.slug,
$wpdb->term_taxonomy.parent, $wpdb->term_taxonomy.description FROM
$wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id =
$wpdb->term_taxonomy.term_id AND $wpdb->terms.name != 'Blogroll' AND
$wpdb->term_taxonomy.taxonomy = 'category' $inExcludeQuery
$catSortColumn
$catSortOrder";
$postquery = "SELECT $wpdb->terms.term_id, $wpdb->terms.name,
$wpdb->terms.slug, $wpdb->term_taxonomy.count, $wpdb->posts.id,
$wpdb->posts.post_title, $wpdb->posts.post_name,
date($wpdb->posts.post_date) as 'date' FROM $wpdb->posts, $wpdb-
>terms,
$wpdb->term_taxonomy, $wpdb->term_relationships WHERE $wpdb-
>posts.id =
$wpdb->term_relationships.object_id AND $wpdb-
>posts.post_status='publish'
AND $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id AND
$wpdb->term_relationships.term_taxonomy_id =
$wpdb->term_taxonomy.term_taxonomy_id AND $wpdb-
>term_taxonomy.taxonomy =
'category' $isPage $postSortColumn $postSortOrder";
$categories = $wpdb->get_results($catquery);
$posts = $wpdb->get_results($postquery);
I use this function to print out arrays:
function print_format_array($array_name) {
echo 'This array contains: ';
echo '<pre>';
ksort($array_name);
print_r($array_name);
echo '</pre>';
echo '--- end array listing ----';
}
options:
http://pastebin.com/m3c4cccae
Posts:
http://pastebin.com/m4d5c61bc
Categories:
http://pastebin.com/m5f33ebdf
function getDepth assigns a depth to each category,
The difficult part of all this for me is to plan the logic.
I appreciate any help or suggestions.
Thanx.
On Jan 2, 2009, at 1:24 AM, Mike Schinkel wrote:
> Gaaack! That's a lot of code.
>
> Which is your entry point? make_def_list()? Is yes, run the
> following
> code for me in the same place you'd call that function and paste the
> output
> to http://pastebin.com/ and reply with the URL it gives you:
----------
Daiv Mowbray
daiv at daivmowbray.com
----------
More information about the wp-hackers
mailing list