3 * Bookmark Template Functions for usage in Themes
10 * 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,
16 * what is between, before, and after can be changed. The link itself will be
19 * This function is used internally by wp_list_bookmarks() and should not be
22 * The defaults for overwriting are:
23 * 'show_updated' - Default is 0 (integer). Will show the time of when the
24 * bookmark was last updated.
25 * 'show_description' - Default is 0 (integer). Whether to show the description
27 * 'show_images' - Default is 1 (integer). Whether to show link image if
29 * 'before' - Default is '<li>' (string). The html or text to prepend to each
31 * 'after' - Default is '</li>' (string). The html or text to append to each
33 * 'between' - Default is '\n' (string). The string for use in between the link,
34 * description, and image.
35 * 'show_rating' - Default is 0 (integer). Whether to show the link rating.
39 * @usedby wp_list_bookmarks()
41 * @param array $bookmarks List of bookmarks to traverse
42 * @param string|array $args Optional. Overwrite the defaults.
43 * @return string Formatted output in HTML
45 function _walk_bookmarks($bookmarks, $args = '' ) {
47 'show_updated' => 0, 'show_description' => 0,
48 'show_images' => 1, 'before' => '<li>',
49 'after' => '</li>', 'between' => "\n",
53 $r = wp_parse_args( $args, $defaults );
54 extract( $r, EXTR_SKIP );
56 $output = ''; // Blank string to start with.
58 foreach ( (array) $bookmarks as $bookmark ) {
59 if ( !isset($bookmark->recently_updated) )
60 $bookmark->recently_updated = false;
62 if ( $show_updated && $bookmark->recently_updated )
63 $output .= get_option('links_recently_updated_prepend');
66 if ( !empty($bookmark->link_url) )
67 $the_link = clean_url($bookmark->link_url);
69 $rel = $bookmark->link_rel;
71 $rel = ' rel="' . $rel . '"';
73 $desc = attribute_escape(sanitize_bookmark_field('link_description', $bookmark->link_description, $bookmark->link_id, 'display'));
74 $name = attribute_escape(sanitize_bookmark_field('link_name', $bookmark->link_name, $bookmark->link_id, 'display'));
78 if ( '00' != substr($bookmark->link_updated_f, 0, 2) ) {
80 $title .= sprintf(__('Last updated: %s'), date(get_option('links_updated_date_format'), $bookmark->link_updated_f + (get_option('gmt_offset') * 3600)));
85 $title = ' title="' . $title . '"';
87 $alt = ' alt="' . $name . '"';
89 $target = $bookmark->link_target;
91 $target = ' target="' . $target . '"';
93 $output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>';
95 if ( $bookmark->link_image != null && $show_images ) {
96 if ( strpos($bookmark->link_image, 'http') !== false )
97 $output .= "<img src=\"$bookmark->link_image\" $alt $title />";
98 else // If it's a relative path
99 $output .= "<img src=\"" . get_option('siteurl') . "$bookmark->link_image\" $alt $title />";
106 if ( $show_updated && $bookmark->recently_updated )
107 $output .= get_option('links_recently_updated_append');
109 if ( $show_description && '' != $desc )
110 $output .= $between . $desc;
113 $output .= $between . get_linkrating($bookmark);
116 $output .= "$after\n";
123 * Retrieve or echo all of the bookmarks
125 * List of default arguments are as follows:
126 * 'orderby' - Default is 'name' (string). How to order the links by. String is
127 * based off of the bookmark scheme.
128 * 'order' - Default is 'ASC' (string). Either 'ASC' or 'DESC'. Orders in either
129 * ascending or descending order.
130 * 'limit' - Default is -1 (integer) or show all. The amount of bookmarks to
132 * 'category' - Default is empty string (string). Include the links in what
134 * 'category_name' - Default is empty string (string). Get links by category
136 * 'hide_invisible' - Default is 1 (integer). Whether to show (default) or hide
137 * links marked as 'invisible'.
138 * 'show_updated' - Default is 0 (integer). Will show the time of when the
139 * bookmark was last updated.
140 * 'echo' - Default is 1 (integer). Whether to echo (default) or return the
141 * formatted bookmarks.
142 * 'categorize' - Default is 1 (integer). Whether to show links listed by
143 * category (default) or show links in one column.
145 * These options define how the Category name will appear before the category
146 * links are displayed, if 'categorize' is 1. If 'categorize' is 0, then it will
147 * display for only the 'title_li' string and only if 'title_li' is not empty.
148 * 'title_li' - Default is 'Bookmarks' (translatable string). What to show
149 * before the links appear.
150 * 'title_before' - Default is '<h2>' (string). The HTML or text to show before
151 * the 'title_li' string.
152 * 'title_after' - Default is '</h2>' (string). The HTML or text to show after
153 * the 'title_li' string.
154 * 'class' - Default is 'linkcat' (string). The CSS class to use for the
157 * 'category_before' - Default is '<li id="%id" class="%class">'. String must
158 * contain '%id' and '%class' to get
159 * the id of the category and the 'class' argument. These are used for
160 * formatting in themes.
161 * Argument will be displayed before the 'title_before' argument.
162 * 'category_after' - Default is '</li>' (string). The HTML or text that will
163 * appear after the list of links.
165 * These are only used if 'categorize' is set to 1 or true.
166 * 'category_orderby' - Default is 'name'. How to order the bookmark category
167 * based on term scheme.
168 * 'category_order' - Default is 'ASC'. Set the order by either ASC (ascending)
169 * or DESC (descending).
171 * @see _walk_bookmarks() For other arguments that can be set in this function
172 * and passed to _walk_bookmarks().
173 * @see get_bookmarks() For other arguments that can be set in this function and
174 * passed to get_bookmarks().
175 * @link http://codex.wordpress.org/Template_Tags/wp_list_bookmarks
178 * @uses _list_bookmarks() Used to iterate over all of the bookmarks and return
180 * @uses get_terms() Gets all of the categories that are for links.
182 * @param string|array $args Optional. Overwrite the defaults of the function
183 * @return string|null Will only return if echo option is set to not echo.
184 * Default is not return anything.
186 function wp_list_bookmarks($args = '') {
188 'orderby' => 'name', 'order' => 'ASC',
189 'limit' => -1, 'category' => '', 'exclude_category' => '',
190 'category_name' => '', 'hide_invisible' => 1,
191 'show_updated' => 0, 'echo' => 1,
192 'categorize' => 1, 'title_li' => __('Bookmarks'),
193 'title_before' => '<h2>', 'title_after' => '</h2>',
194 'category_orderby' => 'name', 'category_order' => 'ASC',
195 'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">',
196 'category_after' => '</li>'
199 $r = wp_parse_args( $args, $defaults );
200 extract( $r, EXTR_SKIP );
205 //Split the bookmarks into ul's for each category
206 $cats = get_terms('link_category', array('name__like' => $category_name, 'include' => $category, 'exclude' => $exclude_category, 'orderby' => $category_orderby, 'order' => $category_order, 'hierarchical' => 0));
208 foreach ( (array) $cats as $cat ) {
209 $params = array_merge($r, array('category'=>$cat->term_id));
210 $bookmarks = get_bookmarks($params);
211 if ( empty($bookmarks) )
213 $output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before);
214 $catname = apply_filters( "link_category", $cat->name );
215 $output .= "$title_before$catname$title_after\n\t<ul class='xoxo blogroll'>\n";
216 $output .= _walk_bookmarks($bookmarks, $r);
217 $output .= "\n\t</ul>\n$category_after\n";
220 //output one single list using title_li for the title
221 $bookmarks = get_bookmarks($r);
223 if ( !empty($bookmarks) ) {
224 if ( !empty( $title_li ) ){
225 $output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before);
226 $output .= "$title_before$title_li$title_after\n\t<ul class='xoxo blogroll'>\n";
227 $output .= _walk_bookmarks($bookmarks, $r);
228 $output .= "\n\t</ul>\n$category_after\n";
230 $output .= _walk_bookmarks($bookmarks, $r);
235 $output = apply_filters( 'wp_list_bookmarks', $output );