Function and usage of get_linksbyname_withrating() in wordpress

Question

Answers ( 1 )

    0
    2024-01-07T11:55:54+00:00

    The get_linksbyname_withrating() function in WordPress is designed to retrieve and display links from a specific category, complete with optional rating stars or characters. This function is particularly useful for organizing and presenting links in a structured and visually appealing way on your WordPress site. Here's a detailed explanation of the function and its parameters:

    Function:

    get_linksbyname_withrating()

    Description:

    • This function gets links associated with a specified category (cat_name) and displays them, optionally including rating stars or characters.
    • It is related to get_bookmarks() function in WordPress.

    Parameters:

    1. $cat_name (string, optional):

      • Specifies the category name of the links.
      • If no matching category is found, it defaults to using all categories.
      • Default value: 'noname'.
    2. $before (string, optional):

      • HTML content to output before each link.
      • Default value: '' (empty string).
    3. $after (string, optional):

      • HTML content to output after each link.
      • Default value: '<br />' (line break).
    4. $between (string, optional):

      • HTML content to output between the link/image and its description.
      • Not used if $show_images is false or not defined.
      • Default value: ' ' (space).
    5. $show_images (bool, optional):

      • Determines whether to show images (if defined) for each link.
      • Default value: true.
    6. $orderby (string, optional):

      • Specifies the order in which to output the links.
      • Possible values: 'id', 'name', 'url', 'description', 'rating', 'owner'. Prefixing with an underscore reverses the order.
      • Special value 'rand' displays links in a random order.
      • Default value: 'id'.
    7. $show_description (bool, optional):

      • Whether to show the description of each link (if $show_images is false or not defined).
      • Default value: true.
    8. $limit (int, optional):

      • Limits the number of entries displayed.
      • -1 indicates no limit.
      • Default value: -1.
    9. $show_updated (int, optional):

      • Whether to show the last updated timestamp for each link.
      • Default value: 0 (do not show).

    Sample Usage:

    <?php
    // Display links from a category 'myCategory' with default settings
    get_linksbyname_withrating('myCategory');
    
    // Display links with specific parameters
    get_linksbyname_withrating('myCategory', '<p>', '</p>', ' - ', true, 'name', true, 10, 1);
    ?>
    

    In this example, links from the category 'myCategory' are displayed. The first usage shows them with default settings. The second usage customizes the output with specific HTML tags, ordering by name, showing descriptions, limiting to 10 entries, and showing the last updated timestamp.

Leave an answer