• Hi, i’m this to show a list of child category and the descripton:

    [please use the ‘code’ button to mark any posted code]

    <?php
    $args=array(
    'orderby' => 'name',
    'order' => 'ASC',
    'child_of' => 4
    );
    $categories=get_categories($args);
    foreach($categories as $category) {
    echo '
    <li>';
    echo '<h3><a>term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></h3> ';
    echo '<p>'. $category->description . '</p>';
    echo '</li>
    ';
    }
    ?>

    And in my theme show:

    News (ID 4) – Hidden – OK!
    – Music OK
    – Shows OK
    – Books OK
    – – Category Book 1 – NO

    What can i do to hidden a “child-child” category? In my exemplo, i dont want show the “Category Book 1”. I try using in “$args” the line ‘depth => 1″.

    Some idea? Tks!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Try adding 'hierarchical' => false to your $args array?

    p.s. code must be placed between backticks, or within <code> tags, and should include no more than about 10 lines of code.

    use the ‘parent’ parameter instead ‘child_of’

    parent
    (integer) Display only categories that are direct descendants (i.e. children only) of the category identified by its ID. This does NOT work like the ‘child_of’ parameter. There is no default for this parameter. [In 2.8.4]

    https://codex.www.ads-software.com/Function_Reference/get_categories

    Thread Starter danielmhd

    (@danielmhd)

    Sorry , i dont use ‘code’.

    I tryed this two options, but dont work .. More ideas?
    When i used, nothing change..

    just checking back:
    using this below did not work?

    $args=array(
    'orderby' => 'name',
    'order' => 'ASC',
    'parent' => 4
    );

    can you post a link to your site to illustrate your problem?

    Sorry , i dont use ‘code’.

    What does that mean? If you post code, you must escape it, using one of the two methods.

    @chip
    this is @danielmhd excusing that he didn’t know about marking code ??

    Thread Starter danielmhd

    (@danielmhd)

    When i wrote the first time, a paste the php here without the code tag and mess this page…

    @alchymyth,

    The site is https://www.eucurtojesus.com.br
    At the left sidebar, with pink color, you can see the “Livros” and “categoria de livros 1”. The second link is child from the first (Livros or Books).

    All links in this area is child from another category with ID 4.
    Abs!

    are you using the ‘parent’ parameter, i.e. this code below?

    <?php
    $args=array(
    'orderby' => 'name',
    'order' => 'ASC',
    'parent' => 4
    );
    $categories=get_categories($args);
    foreach($categories as $category) {
    echo '
    <li>';
    echo '<h3><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></h3> ';
    echo '<p>'. $category->description . '</p>';
    echo '</li>
    ';
    }
    ?>
    Thread Starter danielmhd

    (@danielmhd)

    hmm thanks @alchymyth! I used the “parent” wrong. Now its Ok!!! ?? Thanks!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Remove a child category’ is closed to new replies.