Hallo!
Also ich habe für meine
Linkseite einfach die internen
WP-Funktionen (Stand
Wp 2.3.3) in meine functions.php kopiert und hier und da etwas angepasst. Ich weiß jetzt gerade gar nicht, was ich an der get_links-Funktion verändert hatte. Anyway, schau Dir den Code mal an, vielleicht kannst Du ihn ja brauchen. Dass statt der notes die description ausgegeben wird, wenn keine notes da sind, kann man mit einer Zeile noch ergänzen.
Noch mal für alle: Das folgende ist Stand
WP 2.3.3. Kann sein, dass man es für
WP 2.5 anpassen müsste bzw. dass die Methoden intern in 2.5 verändert wurden (Fehler behoben, besser gemacht etc.).
PHP-Code:
/**
* Outputs a list of all links, listed by category, using the settings in
* $wpdb->linkcategories and output it as a nested HTML unordered list.
* Differences to the WP function: Outputs h3 instead of h2, outputs the count
* of links behind the category name.
*
* @param order Defines how to sort the link categories. Possible values are
* 'name' and 'id'. Optional, defaults to 'name'. Use '_name' or '_id' to
* reverse the sort direction.
* @param cats A list of categories. If not provided, all link categories will
* be retrieved from the database, omitting empty categories.
* @return The overall count of displayed links.
*/
function dor_get_links_list($order = 'name', $cats) {
/* String */ $links = null;
/* String */ $baseIndentation = ' ';
/* int */ $linkCount = 0;
/* int */ $countAll = 0;
// handle the order by and the sort direction parameters
$order = strtolower($order);
$direction = 'ASC';
if (substr($order, 0, 1) === '_') {
$direction = 'DESC';
$order = substr($order, 1);
}
if (!isset($direction)) {
$direction = '';
}
// get the link categories (omitting empty categories)
if ($cats == null) {
$cats = get_categories("type=link&orderby=$order&order=$direction");
}
// display the categories
if ($cats) {
foreach ((array) $cats as $category) {
// get the links for the category and count them
$links = dor_get_links($category->cat_ID, "\n" . $baseIndentation . ' ', true, 'name', true, -1, false);
$linkCount = substr_count($links, '<a href');
$countAll += $linkCount;
if ($linkCount < 1) {
continue;
}
// display the category name
echo '<li id="linkcat-' . $category->cat_ID . '" class="linkcat"><h3>' . $category->cat_name
. ' <span class="count">(' . $linkCount . ")</span></h3>\n$baseIndentation <ul>\n";
// display the links
echo $links;
// close the category
echo "\n$baseIndentation </ul>\n$baseIndentation </li>\n";
} /* end foreach category */
} /* end if categories */
// return the overall link count
return $countAll;
}
/**
* Gets the links associated with the given category.
*
* @param category The category to use. If no category is supplied, the
* function gets links for all categories.
* @param between String to output between elements within the list element
* (between link and notes, notes and update time).
* @param show_images True to show link images (if defined), false to not show
* images.
* @param orderby The order to output the links, e.g. 'id', 'name', 'url',
* 'description', or 'rating'. Or maybe owner. If you start the name with an
* underscore, the order will be reversed. You can also specify 'rand' as the
* order which will return links in a random order.
* @param show_notes Whether to show the notes.
* @param limit Limit to X links. If not specified, all links are shown.
* @param echo Whether to echo the results, or return them instead.
* @return The html to output if echo is true.
*/
function dor_get_links($category = -1,
$between = ' ',
$show_images = true,
$orderby = 'name',
$show_notes = true,
$limit = -1,
$echo = true) {
global $wpdb;
// initialize parameters
$order = 'ASC';
if (substr($orderby, 0, 1) == '_') {
$order = 'DESC';
$orderby = substr($orderby, 1);
}
if ($category == -1) { //get_bookmarks uses '' to signify all categories
$category = '';
}
// get the links
$results = get_bookmarks("category=$category&orderby=$orderby&order=$order&show_updated=0&limit=$limit");
if (!$results) {
return;
}
// build the output
$output = '';
foreach ((array) $results as $row) {
// get link data
$the_link = '#';
if (!empty($row->link_url)) {
$the_link = clean_url($row->link_url);
}
$rel = $row->link_rel;
if ($rel != '') {
$rel = ' rel="' . $rel . '"';
}
$desc = attribute_escape($row->link_description);
$name = attribute_escape($row->link_name);
$notes = attribute_escape($row->link_notes);
$title = $desc;
if ($title != '') {
$title = ' title="' . $title . '"';
}
$alt = ' alt="' . $name . '"';
$target = $row->link_target;
if ($target != '') {
$target = ' target="' . $target . '"';
}
// output the link itself
$output .= ' <li id="link' . $row->link_id . '">'
. '<a href="' . $the_link . '"' . $rel . $title . $target. '>';
if (($row->link_image != null) && $show_images) {
if (strpos($row->link_image, 'http') !== false) {
$output .= "<img src=\"$row->link_image\" $alt $title />";
} else { // if it's a relative path
$output .= "<img src=\"" . get_option('siteurl') . "$row->link_image\" $alt $title />";
}
} else {
$output .= $name;
}
$output .= '</a>';
// output the description
if ($show_notes && ($notes != '')) {
$output .= $between . '<span class="linkDescription">' . $notes . '</span>';
}
$output .= " </li>\n";
} /* end foreach link */
// echo or return the output
if (!$echo) {
return $output;
}
echo $output;
}