wp_list_bookmarks()
Displays a list of links specified on the "Administration > Links" page.
This template tag allows you to control which links to display, how to sort them, etc.
Note: wp_list_bookmarks() completely replaces the now deprecated functions get_links_list() and get_links().
Hooks from the function
Returns
null|String. or outputs the HTML code of the list of links.
Usage Template
<?php
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'limit' => -1,
'category' => '',
'exclude_category' => '',
'category_name' => '',
'category_orderby' => 'name',
'category_order' => 'ASC',
'categorize' => 1,
'title_li' => __('Bookmarks'),
'class' => 'linkcat',
'show_private' => 0 ,
'include' => '',
'exclude' => '',
'before' => '<li>',
'after' => '</li>',
'category_before' => '<li id=%id class=%class>',
'category_after' => '</li>' ,
'title_before' => '<h2>',
'title_after' => '</h2>',
'link_before' => '',
'link_after' => '',
'between' => '',
'show_images' => 1,
'show_description' => 0,
'show_name' => 0,
'show_rating' => 0,
'hide_invisible' => 1,
'echo' => 1 ,
);
wp_list_bookmarks( $args );
?>
Usage
<?php wp_list_bookmarks( $args ); ?>
- $args(string/array)
- Array of arguments according to which the list will be formed (see below).
Default: default parameters
Arguments of the $args parameter
- categorize(boolean)
- Whether to separate links by categories or not. Default is "yes" (true), i.e., if links have 2 or more categories, they will be visually separated.
Default: true - category(string)
- ID of categories (comma-separated) whose links need to be shown. By default, links from all categories are displayed.
Default: '' - exclude_category(string)
- ID of categories (comma-separated) whose links need to be excluded from display. By default, all links are displayed.
Default: '' - category_name(string)
- The name of the category whose link needs to be shown.
Default: '' - category_before(string)
- Text to be shown before each category. Default: '<li id="[category id]" class="linkcat">'.
Default: '<li id="[category id]" class="linkcat">' - category_after(string)
- Text that will be shown after each category. Default: '</li>'.
Default: '</li>' - class(string)
- Class that will be specified for each category of links.
Default: 'linkcat' - category_orderby(string)
Key by which to sort the categories of links. Can be:
name- sort by name - default;id- sort by ID of categories;slug- by slug (alternative name);count- by the number of links in the category;term_group(not used).
Default: 'name'
- category_order(string)
Sorting direction, can be:
ASC- in order;DESC- in reverse order.
Default: 'ASC'
- title_li(string)
- Text before the title of the list of links. Default __('Bookmarks'). __('') is used for localization.
Used only when the "categorize" parameter is set to false (otherwise, the titles will be the names of the categories).
If this parameter is set to false, the title will not be used, and the list will not be "wrapped" in <ul>, </ul> tags (this effect also works only when the "categorize" parameter is set to false).
Default: '__('Bookmarks')' - title_before(string)
- Text before the title. Works if "categorize=1" or text is set for the title_li parameter.
Default: '<h2>' - title_after(string)
- Text after the title. Works if "categorize=1" or text is set for the title_li parameter.
Default: '</h2>' - show_private(boolean)
- Whether the category and links should be shown even if the category has a "private" status. By default, links from private categories will not be shown (false).
Default: false - include(string)
- ID of links (comma-separated). For example, 'include=1,3,6' means the list will consist of links 1,3,6.
This parameter disables the category, category_name, and exclude parameters.
Default: '' - exclude(string)
- ID of links that need to be excluded from display in the list.
Default: '' - orderby(string)
Key by which the list of links will be sorted. Multiple keys can be specified separated by commas. Possible values:
id- sorting by ID;url- by the value of the url field;name- by name - default;targetdescription- by description;owner- by the user who added the link on the link management page;rating- by rating;updatedrelnotesrsslength- by the length of the link name;rand- output links in random order.
Default: 'name'
- order(string)
- Sorting direction of links. ASC - in order, DESC - in reverse order.
Default: 'ASC' - limit(number)
- The maximum number of links to be shown. -1 removes the limit and all links will be shown.
Default: '-1' - before(string)
- Text that will be shown before each link. Default <li>.
Default: '<li>' - after(string)
- Text that will be shown after each link. Default </li>.
Default: '</li>' - link_before(string)
- Text that will be shown before the anchor of each link. Inside the <a> tag. This parameter was added in version 2.7.
Default: '' - link_after(string)
- Text that will be shown after the anchor of each link. Inside the <a> tag. This parameter was added in version 2.7.
Default: '' - between(string)
- Text that will be placed between each link/image and the description of the link. Default \n (new line).
Default: "\n" - show_images(boolean)
- Whether to show (1) the image for the link or not (0). By default, the image is shown if it exists - 1/true.
Default: '1' - show_description(boolean)
- Whether to show the description for the link (1) or not (0). Actually, when
show_images= 0 or the image is not defined. By default 0 - do not show description. - show_name(boolean)
- Whether to show the link text (1) or not (0). Works when
show_images= 1. (added in version 2.7). - show_rating(boolean)
- Whether to show the rating (1) or not (0).
- show_updated(boolean)
- Whether to show (1) or not (0) the update date. (I haven't figured out how this parameter works).
Default: '' - hide_invisible(boolean)
- Whether to show links even if the "visibility" parameter is set to "no". Display is controlled by admin panel settings (1) or not (0).
Default: 1 - display is controlled from the admin panel - echo(boolean)
- Output the result on the screen (1) or return for processing (0).
Default: true
Examples
#1 List of links of bookmarks
Show a list of links, the title of which will be "Links", the list items will be "wrapped" in the tag <li>, the title in the tag <h2>.
<?php wp_list_bookmarks( 'title_li=&category_before=&category_after=' ); ?>
#2 Removing the header from a list of links
Example of removing a header from a list. Useful when you need to set your own header.
<?php wp_list_bookmarks( 'title_li=&categorize=0' ); ?>
#3 Links from this category
Example of link output from link category 2 (category=2) wrapped in span tag (before=<span>&after=</span> ), using images for each link (show_images=1), description turned off (show_description=0) and sorted by link itself (orderby=url).
<?php wp_list_bookmarks( 'categorize=0&category=2&before=<span>&after=</span>&show_images=1&show_description=0&orderby=url' ); ?>
#4 Replacing the header with a picture
An example of how you can replace the header of the list with a picture.
wp_list_bookmarks( [ 'categorize' => 0, 'title_before' => '', 'title_after' => '', 'title_li' => '<img src="' . get_bloginfo( "stylesheet_directory" ) . '/images/blogroll.gif" alt="blogroll" />', ] );
#5 Shows Ratings and Timestamp
Displays all bookmarks in an ordered list with descriptions on a new line, does not use images for bookmarks, sorts by bookmark id, shows ratings and last-updated timestamp (Note that the last updated timestamp does not track local modifications. It tracks when whatever the link points to is updated via remote requests to pingomatic.)
<ol> <?php wp_list_bookmarks( 'between=<br />&show_images=0&orderby=id&show_rating=1&show_updated=1' ); ?> </ol>
Notes
- See: _walk_bookmarks()
Changelog
| Since 2.1.0 | Introduced. |