linkcategories and output it as a nested * HTML unordered list. * * Parameters: * order (default 'name') - Sort link categories by 'name' or 'id' * hide_if_empty (default true) - Supress listing empty link categories */ function get_links_sidebar($order = 'name', $hide_if_empty = 'obsolete') { global $wpdb; $order = strtolower($order); // Handle link category sorting if (substr($order,0,1) == '_') { $direction = ' DESC'; $order = substr($order,1); } // if 'name' wasn't specified, assume 'id': $cat_order = ('name' == $order) ? 'cat_name' : 'cat_id'; if (!isset($direction)) $direction = ''; // Fetch the link category data as an array of hashesa $cats = $wpdb->get_results(" SELECT DISTINCT link_category, cat_name, show_images, show_description, show_rating, show_updated, sort_order, sort_desc, list_limit FROM `$wpdb->links` LEFT JOIN `$wpdb->linkcategories` ON (link_category = cat_id) WHERE link_visible = 'Y' AND list_limit <> 0 ORDER BY $cat_order $direction ", ARRAY_A); // Display each category if ($cats) { foreach ($cats as $cat) { // Handle each category. // First, fix the sort_order info $orderby = $cat['sort_order']; $orderby = (bool_from_yn($cat['sort_desc'])?'_':'') . $orderby; // Display the category name // echo '
  • ' . $cat['cat_name'] . "\n\t