Forums

[resolved] wp_list_categories, displaying children links only. (3 posts)

  1. thatguyfromabove
    Member
    Posted 2 years ago #

    I have a wp-based website for an online shop. The items are listed as posts, the navigation is based on categories. For parent category pages (archive.php), I want to have the children categories listed as links. I don't want to code every parent page individually (child_of=x). I've found the following code, but there seems to be an error somewhere, as not only the children categories are listed, but all of the website's categories.

    <?php
    $children = wp_list_categories('title_li=&child_of='.$category->cat_ID.'&echo=0');
    if ($children) { ?>

      <?php echo $children; ?>

    <?php } ?>

  2. thatguyfromabove
    Member
    Posted 1 year ago #

    If anyone is interested, it was just a syntax error. Here is the working version.

    <?php
    $children = wp_list_categories('title_li=&child_of='.$cat.'&echo=0');
    if ($children) { ?>
    <?php echo $children; ?>
    <?php } ?>

  3. websta
    Member
    Posted 1 year ago #

    Thank you, thatguyfromabove. I appreciate the code, and that you came back to post it.

    People like you make WordPress wonderful.

Topic Closed

This topic has been closed to new replies.

About this Topic