The get_linksbyname_withrating() WordPress PHP function retrieves links associated with a specified category and displays rating stars or characters.
Usage
get_linksbyname_withrating($cat_name, $before, $after, $between, $show_images, $orderby, $show_description, $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:
<br />
. - $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
is false or not defined. Default: true. - $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_withrating
Examples
Display links from ‘Web Development’ category
This example retrieves links from the ‘Web Development’ category, displaying them with the default settings.
get_linksbyname_withrating('Web Development');
Display links from ‘Design’ category with custom HTML
This example retrieves links from the ‘Design’ category, with custom HTML before and after each link.
get_linksbyname_withrating('Design', '<li>', '</li>');
Display links without images
This example retrieves links from the ‘Photography’ category, without displaying images.
get_linksbyname_withrating('Photography', '', '', '', false);
Display links ordered by rating
This example retrieves links from the ‘Travel’ category, ordered by their rating.
get_linksbyname_withrating('Travel', '', '', '', true, 'rating');
Display links with a limit
This example retrieves up to 5 links from the ‘Health’ category.
get_linksbyname_withrating('Health', '', '', '', true, 'id', true, 5);