Using WordPress ‘get_linksbyname()’ PHP function

The get_linksbyname() WordPress PHP function retrieves the links associated with a specified category name.

Usage

get_linksbyname($cat_name, $before, $after, $between, $show_images, $orderby, $show_description, $show_rating, $limit, $show_updated);

Parameters

  • $cat_name (string) – Optional. The category name to use. If no match is found, uses all. Default: ‘noname’.
  • $before (string) – Optional. The HTML to output before the link. Default: ”.
  • $after (string) – Optional. The HTML to output after the link. Default: ‘
    ‘.
  • $between (string) – Optional. The HTML to output between the link/image and its description. Not used if no image or $show_images is true. Default: ‘ ‘.
  • $show_images (bool) – Optional. Whether to show images (if defined). Default: true.
  • $orderby (string) – Optional. The order to output the links. E.g. ‘id’, ‘name’, ‘url’, ‘description’, ‘rating’, or ‘owner’. Default: ‘id’. If you start the name with an underscore, the order will be reversed. Specifying ‘rand’ as the order will return links in a random order. Default: ‘id’.
  • $show_description (bool) – Optional. Whether to show the description if show_images=false/not defined. Default: true.
  • $show_rating (bool) – Optional. Show rating stars/chars. Default: false.
  • $limit (int) – Optional. Limit to X entries. If not specified, all entries are shown. Default: -1.
  • $show_updated (int) – Optional. Whether to show last updated timestamp. Default: 0.

More information

See WordPress Developer Resources: get_linksbyname()

Examples

This code snippet displays all links in the ‘noname’ category, with a line break after each link.

get_linksbyname('noname');

This example displays links in the ‘Friends’ category, wrapped in a <li> element.

get_linksbyname('Friends', '<li>', '</li>');

This example shows links in the ‘Sponsors’ category without their associated images.

get_linksbyname('Sponsors', '', '<br />', ' ', false);

This example displays all links in the ‘Partners’ category, ordered alphabetically by name.

get_linksbyname('Partners', '', '<br />', ' ', true, 'name');

This example shows only the first 5 links in the ‘Affiliates’ category.

get_linksbyname('Affiliates', '', '<br />', ' ', true, 'id', true, false, 5);

Tagged in

Leave a Comment

Your email address will not be published. Required fields are marked *