get_links

Gets the links associated with category by id.

Description

(null|string) get_links( (int) $category = -1, (string) $before = '', $after = '<br />', (string) $between = ' ', (constant) $show_images = true, (string) $orderby = 'name', (constant) $show_description = true, (constant) $show_rating = false, (int) $limit = -1, (int) $show_updated = 1, (constant) $echo = true ); 

Returns (null|string)

Parameters (11)

0. $category — Optional. (int) => -1
The category to use. If no category supplied uses all
1. $before — Optional. (string) => ''
The html to output before the link
2. $after — Optional. (string) => '
'
The html to output after the link
3. $between — Optional. (string) => ' '
The html to output between the link/image and its description. Not used if no image or show_images == true
4. $show_images — Optional. (constant) => true
Whether to show images (if defined).
5. $orderby — Optional. (string) => 'name'
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.
6. $show_description — Optional. (constant) => true
Whether to show the description if show_images=false/not defined.
7. $show_rating — Optional. (constant) => false
Show rating stars/chars
8. $limit — Optional. (int) => -1
Limit to X entries. If not specified, all entries are shown.
9. $show_updated — Optional. (int) => 1
Whether to show last updated timestamp
10. $echo — Optional. (constant) => true
Whether to echo the results, or return them instead

Usage

  1. if ( !function_exists( 'get_links' ) ) { 
  2. require_once ABSPATH . WPINC . '/deprecated.php'; 
  3.  
  4. // The category to use. If no category supplied uses all 
  5. $category = -1; 
  6.  
  7. // the html to output before the link 
  8. $before = ''; 
  9.  
  10. // the html to output after the link 
  11. $after = '
    '; 
  12.  
  13. // the html to output between the link/image and its description. 
  14. // Not used if no image or show_images == true 
  15. $between = ' '; 
  16.  
  17. // whether to show images (if defined). 
  18. $show_images = true; 
  19. $orderby = 'name'; 
  20.  
  21. // whether to show the description if show_images=false/not defined. 
  22. $show_description = true; 
  23.  
  24. // show rating stars/chars 
  25. $show_rating = false; 
  26.  
  27. // Limit to X entries. If not specified, all entries are shown. 
  28. $limit = -1; 
  29.  
  30. // whether to show last updated timestamp 
  31. $show_updated = 1; 
  32.  
  33. // whether to echo the results, or return them instead 
  34. $echo = true; 
  35.  
  36. // NOTICE! Understand what this does before running. 
  37. $result = get_links($category, $before, $after, $between, $show_images, $orderby, $show_description, $show_rating, $limit, $show_updated, $echo); 
  38.  

Defined (1)

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

/wp-includes/deprecated.php  
  1. function get_links($category = -1, $before = '', $after = '<br />', $between = ' ', $show_images = true, $orderby = 'name',  
  2. $show_description = true, $show_rating = false, $limit = -1, $show_updated = 1, $echo = true) { 
  3. _deprecated_function( __FUNCTION__, '2.1.0', 'get_bookmarks()' ); 
  4.  
  5. $order = 'ASC'; 
  6. if ( substr($orderby, 0, 1) == '_' ) { 
  7. $order = 'DESC'; 
  8. $orderby = substr($orderby, 1); 
  9.  
  10. if ( $category == -1 ) //get_bookmarks uses '' to signify all categories 
  11. $category = ''; 
  12.  
  13. $results = get_bookmarks(array('category' => $category, 'orderby' => $orderby, 'order' => $order, 'show_updated' => $show_updated, 'limit' => $limit)); 
  14.  
  15. if ( !$results ) 
  16. return; 
  17.  
  18. $output = ''; 
  19.  
  20. foreach ( (array) $results as $row ) { 
  21. if ( !isset($row->recently_updated) ) 
  22. $row->recently_updated = false; 
  23. $output .= $before; 
  24. if ( $show_updated && $row->recently_updated ) 
  25. $output .= get_option('links_recently_updated_prepend'); 
  26. $the_link = '#'; 
  27. if ( !empty($row->link_url) ) 
  28. $the_link = esc_url($row->link_url); 
  29. $rel = $row->link_rel; 
  30. if ( '' != $rel ) 
  31. $rel = ' rel="' . $rel . '"'; 
  32.  
  33. $desc = esc_attr(sanitize_bookmark_field('link_description', $row->link_description, $row->link_id, 'display')); 
  34. $name = esc_attr(sanitize_bookmark_field('link_name', $row->link_name, $row->link_id, 'display')); 
  35. $title = $desc; 
  36.  
  37. if ( $show_updated ) 
  38. if (substr($row->link_updated_f, 0, 2) != '00') 
  39. $title .= ' ('.__('Last updated') . ' ' . date(get_option('links_updated_date_format'), $row->link_updated_f + (get_option('gmt_offset') * HOUR_IN_SECONDS)) . ')'; 
  40.  
  41. if ( '' != $title ) 
  42. $title = ' title="' . $title . '"'; 
  43.  
  44. $alt = ' alt="' . $name . '"'; 
  45.  
  46. $target = $row->link_target; 
  47. if ( '' != $target ) 
  48. $target = ' target="' . $target . '"'; 
  49.  
  50. $output .= '<a href="' . $the_link . '"' . $rel . $title . $target. '>'; 
  51.  
  52. if ( $row->link_image != null && $show_images ) { 
  53. if ( strpos($row->link_image, 'http') !== false ) 
  54. $output .= "<img src=\"$row->link_image\" $alt $title />"; 
  55. else // If it's a relative path 
  56. $output .= "<img src=\"" . get_option('siteurl') . "$row->link_image\" $alt $title />"; 
  57. } else { 
  58. $output .= $name; 
  59.  
  60. $output .= '</a>'; 
  61.  
  62. if ( $show_updated && $row->recently_updated ) 
  63. $output .= get_option('links_recently_updated_append'); 
  64.  
  65. if ( $show_description && '' != $desc ) 
  66. $output .= $between . $desc; 
  67.  
  68. if ($show_rating) { 
  69. $output .= $between . get_linkrating($row); 
  70.  
  71. $output .= "$after\n"; 
  72. } // end while 
  73.  
  74. if ( !$echo ) 
  75. return $output; 
  76. echo $output;