function get_category_children has a line i can't find its purpose; (3 posts)

  1. da_silva
    Posted 9 years ago #

    Hi guys, i am modifying my template and i read this function of wordpress but there is a line that if erased nothing changes so i guess it does nothing.The line is emphasized below.

    function get_category_children($id, $before = '/', $after = '') {
    if ( 0 == $id )
    return '';
    $cat_ids = get_all_category_ids();
    foreach ( $cat_ids as $cat_id ) {
    if ( $cat_id == $id)
    $category = get_category($cat_id);
    if ( $category->category_parent == $id ) {
    $chain .= $before.$category->cat_ID.$after;
    $chain .= get_category_children($category->cat_ID, $before, $after);
    return $chain;

    This is the issued line:
    $chain .= get_category_children($category->cat_ID, $before, $after);

    What's it purpose in the above code and why if erased the function still returns the children of the category transmitted as parameter?

  2. That line makes it recursive. Without it, it's not recursive.

    If you have categories like this:

    ...then calling it on the Parent gives you both the Child and the GrandChild. Without that line, it'll just give you the Child.

    And note that I would really recommend AGAINST editing code when you don't understand what it does. Erasing lines randomly to see what happens is a poor way to figure things out, and very likely to break things. Badly.

  3. da_silva
    Posted 9 years ago #

    :) i'm not erasing lines i just didn't get it what it does so i asked. Actually i'm not modifying anything wordpress comes as default with. It was just a thing i did to see what happends because i didn't understand its purpose. I don't delete things for good, but thanks for making things clear.

Topic Closed

This topic has been closed to new replies.

About this Topic