wp_list_bookmarks

Retrieve or echo all of the bookmarks.

Description

(string|void) wp_list_bookmarks( (string) $args = '' ); 

List of default arguments are as follows:

These options define how the Category name will appear before the category links are displayed, if categorize is 1. If categorize is 0, then it will display for only the title_li string and only if title_li is not empty.

Returns (string|void)

Will only return if echo option is set to not echo. Default is not return anything.

Parameters (1)

0. $args — Optional. (string) => ''
String or array of arguments to list bookmarks.

Options

  • orderby (string) => 'name'

    How to order the links by. Accepts post fields.

  • order (string) => 'ASC'

    Whether to order bookmarks in ascending or descending order. Accepts ASC (ascending) or DESC (descending).

  • limit (int) => -1

    Amount of bookmarks to display. Accepts 1+ or -1 for all.

  • category (string) => ''

    Comma-separated list of category ids to include links from.

  • category_name (string) => ''

    Category to retrieve links for by name.

  • hide_invisible (int|bool) => 1

    Whether to show or hide links marked as invisible.. Accepts 1|true or 0|false.

  • show_updated (int|bool) => 0

    Whether to display the time the bookmark was last updated. Accepts 1|true or 0|false.

  • echo (int|bool) => 1

    Whether to echo or return the formatted bookmarks. Accepts 1|true (echo) or 0|false (return).

  • categorize (int|bool) => 1

    Whether to show links listed by category or in a single column. Accepts 1|true (by category) or 0|false (one column).

  • show_description (int|bool) => 0

    Whether to show the bookmark descriptions. Accepts 1|true or 0|false.

  • title_li (string) => 'Bookmarks'

    What to show before the links appear.

  • title_before (string) => '

    '

    The HTML or text to prepend to the $title_li string.

  • title_after (string) => ''

    The HTML or text to append to the $title_li string.

  • class (string) => 'linkcat'

    The CSS class to use for the $title_li.

  • category_before (string) => '
  • category_after (string) => '
  • '

    The HTML or text to append to $title_after if $categorize is true.

  • category_orderby (string) => 'name'

    How to order the bookmark category based on term scheme if $categorize is true.

array(

    /**
     * How to order the links by. Accepts post fields.
     *
     * @type string
     * @default 'name'
     */
    'orderby' => 'name',

    /**
     * Whether to order bookmarks in ascending or descending order. Accepts 'ASC' (ascending) or
     * 'DESC' (descending).
     *
     * @type string
     * @default 'ASC'
     */
    'order' => 'ASC',

    /**
     * Amount of bookmarks to display. Accepts 1+ or -1 for all.
     *
     * @type int
     * @default -1
     */
    'limit' => -1,

    /**
     * Comma-separated list of category ids to include links from.
     *
     * @type string
     * @default ''
     */
    'category' => '',

    /**
     * Category to retrieve links for by name.
     *
     * @type string
     * @default ''
     */
    'category_name' => '',

    /**
     * Whether to show or hide links marked as 'invisible'. Accepts 1|true or 0|false.
     *
     * @type int|bool
     * @default 1
     */
    'hide_invisible' => 1,

    /**
     * Whether to display the time the bookmark was last updated. Accepts 1|true or 0|false.
     *
     * @type int|bool
     */
    'show_updated' => 0,

    /**
     * Whether to echo or return the formatted bookmarks. Accepts 1|true (echo) or 0|false
     * (return).
     *
     * @type int|bool
     * @default 1
     */
    'echo' => 1,

    /**
     * Whether to show links listed by category or in a single column. Accepts 1|true (by category) or
     * 0|false (one column).
     *
     * @type int|bool
     * @default 1
     */
    'categorize' => 1,

    /**
     * Whether to show the bookmark descriptions. Accepts 1|true or 0|false.
     *
     * @type int|bool
     */
    'show_description' => 0,

    /**
     * What to show before the links appear.
     *
     * @type string
     * @default 'Bookmarks'
     */
    'title_li' => 'Bookmarks',

    /**
     * The HTML or text to prepend to the $title_li string.
     *
     * @type string
     * @default '

' */ 'title_before' => '

', /** * The HTML or text to append to the $title_li string. * * @type string * @default '

' */
'title_after' => '

'
, /** * The CSS class to use for the $title_li. * * @type string * @default 'linkcat' */ 'class' => 'linkcat', /** * The HTML or text to prepend to $title_before if $categorize is true. String must contain '%id' * and '%class' to inherit the category ID and the $class argument used for formatting in themes. * * @type string * @default '
  • category_before' => '
  • /** * The HTML or text to append to $title_after if $categorize is true. * * @type string * @default '
  • ' */
    'category_after' => '', /** * How to order the bookmark category based on term scheme if $categorize is true. * * @type string * @default 'name' */ 'category_orderby' => 'name' );


    Usage

    1. if ( !function_exists( 'wp_list_bookmarks' ) ) { 
    2. require_once ABSPATH . WPINC . '/bookmark-template.php'; 
    3.  
    4. // Optional. String or array of arguments to list bookmarks. 
    5. $args = array( 
    6. 'orderby' => 'name', 
    7. 'order' => 'ASC', 
    8. 'limit' => -1, 
    9. 'category' => '', 
    10. 'category_name' => '', 
    11. 'hide_invisible' => 1, 
    12. 'show_updated' => 0, 
    13. 'echo' => 1, 
    14. 'categorize' => 1, 
    15. 'show_description' => 0, 
    16. 'title_li' => 'Bookmarks', 
    17. 'title_before' => '', 
    18. 'title_after' => '', 
    19. 'class' => 'linkcat', 
    20. 'category_orderby' => 'name' 
    21. ); 
    22.  
    23. // NOTICE! Understand what this does before running. 
    24. $result = wp_list_bookmarks($args); 
    25.  

    Defined (1)

    The function is defined in the following location(s).

    /wp-includes/bookmark-template.php  
    1. function wp_list_bookmarks( $args = '' ) { 
    2. $defaults = array( 
    3. 'orderby' => 'name', 'order' => 'ASC',  
    4. 'limit' => -1, 'category' => '', 'exclude_category' => '',  
    5. 'category_name' => '', 'hide_invisible' => 1,  
    6. 'show_updated' => 0, 'echo' => 1,  
    7. 'categorize' => 1, 'title_li' => __('Bookmarks'),  
    8. 'title_before' => '<h2>', 'title_after' => '</h2>',  
    9. 'category_orderby' => 'name', 'category_order' => 'ASC',  
    10. 'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">',  
    11. 'category_after' => '</li>' 
    12. ); 
    13.  
    14. $r = wp_parse_args( $args, $defaults ); 
    15.  
    16. $output = ''; 
    17.  
    18. if ( ! is_array( $r['class'] ) ) { 
    19. $r['class'] = explode( ' ', $r['class'] ); 
    20. $r['class'] = array_map( 'sanitize_html_class', $r['class'] ); 
    21. $r['class'] = trim( join( ' ', $r['class'] ) ); 
    22.  
    23. if ( $r['categorize'] ) { 
    24. $cats = get_terms( 'link_category', array( 
    25. 'name__like' => $r['category_name'],  
    26. 'include' => $r['category'],  
    27. 'exclude' => $r['exclude_category'],  
    28. 'orderby' => $r['category_orderby'],  
    29. 'order' => $r['category_order'],  
    30. 'hierarchical' => 0 
    31. ) ); 
    32. if ( empty( $cats ) ) { 
    33. $r['categorize'] = false; 
    34.  
    35. if ( $r['categorize'] ) { 
    36. // Split the bookmarks into ul's for each category 
    37. foreach ( (array) $cats as $cat ) { 
    38. $params = array_merge( $r, array( 'category' => $cat->term_id ) ); 
    39. $bookmarks = get_bookmarks( $params ); 
    40. if ( empty( $bookmarks ) ) { 
    41. continue; 
    42. $output .= str_replace( 
    43. array( '%id', '%class' ),  
    44. array( "linkcat-$cat->term_id", $r['class'] ),  
    45. $r['category_before'] 
    46. ); 
    47. /** 
    48. * Filters the bookmarks category name. 
    49. * @since 2.2.0 
    50. * @param string $cat_name The category name of bookmarks. 
    51. */ 
    52. $catname = apply_filters( 'link_category', $cat->name ); 
    53.  
    54. $output .= $r['title_before']; 
    55. $output .= $catname; 
    56. $output .= $r['title_after']; 
    57. $output .= "\n\t<ul class='xoxo blogroll'>\n"; 
    58. $output .= _walk_bookmarks( $bookmarks, $r ); 
    59. $output .= "\n\t</ul>\n"; 
    60. $output .= $r['category_after'] . "\n"; 
    61. } else { 
    62. //output one single list using title_li for the title 
    63. $bookmarks = get_bookmarks( $r ); 
    64.  
    65. if ( ! empty( $bookmarks ) ) { 
    66. if ( ! empty( $r['title_li'] ) ) { 
    67. $output .= str_replace( 
    68. array( '%id', '%class' ),  
    69. array( "linkcat-" . $r['category'], $r['class'] ),  
    70. $r['category_before'] 
    71. ); 
    72. $output .= $r['title_before']; 
    73. $output .= $r['title_li']; 
    74. $output .= $r['title_after']; 
    75. $output .= "\n\t<ul class='xoxo blogroll'>\n"; 
    76. $output .= _walk_bookmarks( $bookmarks, $r ); 
    77. $output .= "\n\t</ul>\n"; 
    78. $output .= $r['category_after'] . "\n"; 
    79. } else { 
    80. $output .= _walk_bookmarks( $bookmarks, $r ); 
    81.  
    82. /** 
    83. * Filters the bookmarks list before it is echoed or returned. 
    84. * @since 2.5.0 
    85. * @param string $html The HTML list of bookmarks. 
    86. */ 
    87. $html = apply_filters( 'wp_list_bookmarks', $output ); 
    88.  
    89. if ( ! $r['echo'] ) { 
    90. return $html; 
    91. echo $html;