You were on the right track! The problem is that the function get_links_list() does not accept a link category ID number as a parameter.
What I did was kind of a kludge for now, but it got me going.
First, in links.php, I created a new function called get_single_links_list() that takes the link ID as a parameter:
function get_single_links_list($order = 'name', $hide_if_empty = 'obsolete', $linkcategoryid) {
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
AND cat_id = $linkcategoryid
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 ‘ <li id=”linkcat-‘ . $cat[‘link_category’] . ‘”><h2>’ . $cat[‘cat_name’] . “</h2>\n\t
\n”;
// Call get_links() with all the appropriate params
get_links($cat[‘link_category’],
‘
- ‘,”
“,”\n”,
bool_from_yn($cat[‘show_images’]),
$orderby,
bool_from_yn($cat[‘show_description’]),
bool_from_yn($cat[‘show_rating’]),
$cat[‘list_limit’],
bool_from_yn($cat[‘show_updated’]));
// Close the last category
echo “\n\t
\n\n”;
}
}
}
Next, in widgets.php, around line 650 or so, I added a few blocks of code like this:
function widget_links_2($args) {
// This ONLY works with li/h2 sidebars.
get_single_links_list('name', 'obsolete', 2);
}
Notice that in the list of arguments, the “2” is the link category ID number. The modified function above accepts this number and modifies the database query to list only the single category.
And at the end of widgets.php, I registered the widget:
register_sidebar_widget('My Links', 'widget_links_2');
It’s working great now!
What I will do in the near future is modify the original get_links_list() function to take the category ID as an optional third parameter, rather than have the separate function for it. Being in a bit of a rush today, I don’t have time to tackle it, but for now I have it working.
To create the new function, the only changes I made were to add $linkcategoryid as one of the parameters, which is the first line of my new function:
function get_single_links_list($order = 'name', $hide_if_empty = 'obsolete', $linkcategoryid) {
Then further down, in the queries, I changed this:
WHERE link_visible = 'Y'
AND list_limit <> 0
by adding this just below it:
WHERE link_visible = 'Y'
AND list_limit <> 0
AND cat_id = $linkcategoryid
That’s it!
Note that the word wrapping is killing my code here; hopefully my post makes some sense.