3 * Bookmark Template Functions for usage in Themes
10 * _walk_bookmarks() - The formatted output of a list of bookmarks
12 * The $bookmarks array must contain bookmark objects and will be iterated over
13 * to retrieve the bookmark to be used in the output.
15 * The output is formatted as HTML with no way to change that format. However, what
16 * is between, before, and after can be changed. The link itself will be HTML.
18 * This function is used internally by wp_list_bookmarks() and should not be used by
21 * The defaults for overwriting are:
22 * 'show_updated' - Default is 0 (integer). Will show the time of when the bookmark was last updated.
23 * 'show_description' - Default is 0 (integer). Whether to show the description of the bookmark.
24 * 'show_images' - Default is 1 (integer). Whether to show link image if available.
25 * 'before' - Default is '<li>' (string). The html or text to prepend to each bookmarks.
26 * 'after' - Default is '</li>' (string). The html or text to append to each bookmarks.
27 * 'between' - Default is '\n' (string). The string for use in between the link, description, and image.
28 * 'show_rating' - Default is 0 (integer). Whether to show the link rating.
32 * @usedby wp_list_bookmarks()
34 * @param array $bookmarks List of bookmarks to traverse
35 * @param string|array $args Optional. Overwrite the defaults.
36 * @return string Formatted output in HTML
38 function _walk_bookmarks($bookmarks, $args = '' ) {
40 'show_updated' => 0, 'show_description' => 0,
41 'show_images' => 1, 'before' => '<li>',
42 'after' => '</li>', 'between' => "\n",
46 $r = wp_parse_args( $args, $defaults );
47 extract( $r, EXTR_SKIP );
49 $output = ''; // Blank string to start with.
51 foreach ( (array) $bookmarks as $bookmark ) {
52 if ( !isset($bookmark->recently_updated) )
53 $bookmark->recently_updated = false;
55 if ( $show_updated && $bookmark->recently_updated )
56 $output .= get_option('links_recently_updated_prepend');
59 if ( !empty($bookmark->link_url) )
60 $the_link = clean_url($bookmark->link_url);
62 $rel = $bookmark->link_rel;
64 $rel = ' rel="' . $rel . '"';
66 $desc = attribute_escape(sanitize_bookmark_field('link_description', $bookmark->link_description, $bookmark->link_id, 'display'));
67 $name = attribute_escape(sanitize_bookmark_field('link_name', $bookmark->link_name, $bookmark->link_id, 'display'));
71 if ( '00' != substr($bookmark->link_updated_f, 0, 2) ) {
73 $title .= sprintf(__('Last updated: %s'), date(get_option('links_updated_date_format'), $bookmark->link_updated_f + (get_option('gmt_offset') * 3600)));
78 $title = ' title="' . $title . '"';
80 $alt = ' alt="' . $name . '"';
82 $target = $bookmark->link_target;
84 $target = ' target="' . $target . '"';
86 $output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>';
88 if ( $bookmark->link_image != null && $show_images ) {
89 if ( strpos($bookmark->link_image, 'http') !== false )
90 $output .= "<img src=\"$bookmark->link_image\" $alt $title />";
91 else // If it's a relative path
92 $output .= "<img src=\"" . get_option('siteurl') . "$bookmark->link_image\" $alt $title />";
99 if ( $show_updated && $bookmark->recently_updated )
100 $output .= get_option('links_recently_updated_append');
102 if ( $show_description && '' != $desc )
103 $output .= $between . $desc;
106 $output .= $between . get_linkrating($bookmark);
109 $output .= "$after\n";
116 * wp_list_bookmarks() - Retrieve or echo all of the bookmarks
118 * List of default arguments are as follows:
119 * 'orderby' - Default is 'name' (string). How to order the links by. String is based off of the bookmark scheme.
120 * 'order' - Default is 'ASC' (string). Either 'ASC' or 'DESC'. Orders in either ascending or descending order.
121 * 'limit' - Default is -1 (integer) or show all. The amount of bookmarks to display.
122 * 'category' - Default is empty string (string). Include the links in what category ID(s).
123 * 'category_name' - Default is empty string (string). Get links by category name.
124 * 'hide_invisible' - Default is 1 (integer). Whether to show (default) or hide links marked as 'invisible'.
125 * 'show_updated' - Default is 0 (integer). Will show the time of when the bookmark was last updated.
126 * 'echo' - Default is 1 (integer). Whether to echo (default) or return the formatted bookmarks.
127 * 'categorize' - Default is 1 (integer). Whether to show links listed by category (default) or show links in one column.
129 * These options define how the Category name will appear before the category links are displayed, if 'categorize' is 1.
130 * If 'categorize' is 0, then it will display for only the 'title_li' string and only if 'title_li' is not empty.
131 * 'title_li' - Default is 'Bookmarks' (translatable string). What to show before the links appear.
132 * 'title_before' - Default is '<h2>' (string). The HTML or text to show before the 'title_li' string.
133 * 'title_after' - Default is '</h2>' (string). The HTML or text to show after the 'title_li' string.
134 * 'class' - Default is 'linkcat' (string). The CSS class to use for the 'title_li'.
136 * 'category_before' - Default is '<li id="%id" class="%class">'. String must contain '%id' and '%class' to get
137 * the id of the category and the 'class' argument. These are used for formatting in themes. Argument will be displayed
138 * before the 'title_before' argument.
139 * 'category_after' - Default is '</li>' (string). The HTML or text that will appear after the list of links.
141 * These are only used if 'categorize' is set to 1 or true.
142 * 'category_orderby' - Default is 'name'. How to order the bookmark category based on term scheme.
143 * 'category_order' - Default is 'ASC'. Set the order by either ASC (ascending) or DESC (descending).
145 * @see _walk_bookmarks() For other arguments that can be set in this function and passed to _walk_bookmarks().
146 * @see get_bookmarks() For other arguments that can be set in this function and passed to get_bookmarks().
149 * @uses _list_bookmarks() Used to iterate over all of the bookmarks and return the html
150 * @uses get_terms() Gets all of the categories that are for links.
152 * @param string|array $args Optional. Overwrite the defaults of the function
153 * @return string|null Will only return if echo option is set to not echo. Default is not return anything.
155 function wp_list_bookmarks($args = '') {
157 'orderby' => 'name', 'order' => 'ASC',
158 'limit' => -1, 'category' => '',
159 'category_name' => '', 'hide_invisible' => 1,
160 'show_updated' => 0, 'echo' => 1,
161 'categorize' => 1, 'title_li' => __('Bookmarks'),
162 'title_before' => '<h2>', 'title_after' => '</h2>',
163 'category_orderby' => 'name', 'category_order' => 'ASC',
164 'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">',
165 'category_after' => '</li>'
168 $r = wp_parse_args( $args, $defaults );
169 extract( $r, EXTR_SKIP );
174 //Split the bookmarks into ul's for each category
175 $cats = get_terms('link_category', "category_name=$category_name&include=$category&orderby=$category_orderby&order=$category_order&hierarchical=0");
177 foreach ( (array) $cats as $cat ) {
178 $params = array_merge($r, array('category'=>$cat->term_id));
179 $bookmarks = get_bookmarks($params);
180 if ( empty($bookmarks) )
182 $output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before);
183 $catname = apply_filters( "link_category", $cat->name );
184 $output .= "$title_before$catname$title_after\n\t<ul>\n";
185 $output .= _walk_bookmarks($bookmarks, $r);
186 $output .= "\n\t</ul>\n$category_after\n";
189 //output one single list using title_li for the title
190 $bookmarks = get_bookmarks($r);
192 if ( !empty($bookmarks) ) {
193 if ( !empty( $title_li ) ){
194 $output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before);
195 $output .= "$title_before$title_li$title_after\n\t<ul>\n";
196 $output .= _walk_bookmarks($bookmarks, $r);
197 $output .= "\n\t</ul>\n$category_after\n";
199 $output .= _walk_bookmarks($bookmarks, $r);
204 $output = apply_filters( 'wp_list_bookmarks', $output );