• Resolved albertbarba

    (@albertbarba)


    En un blog que estoy creando he a?adido un trozo de código que lista las categorías hijo a la derecha según la categoría padre donde te encuentres. Hasta aquí bien, pero necesitaria que cuando accedo a una de esas categorías hijo, el menú de categorías no se perdiera. ?Porqué se pierde ahora? Porque al no detectar más categorías hijo anidadas a esa en particular no muestra nada.

    Lo que me interesaría es que se mostraran siempre todas las categorías independienemtente del nivel donde se encuentre dentro de la categoría padre. En el caso de estar en un tercer nivel, que se mostrara así:

    NIVEL PADRE

    • – hijo 1
    • – hijo 2
    • – hijo 3
    • hijo 3.1
    • hijo 3.2
    • -hijo 4

    Espero me haya explicado bien. Podéis ver la problemática en esta dirección

    https://www.profesionalesdelaestetica.com/category/tratamientos/

    Veréis que en el menú lateral salen las subopciones pero cuando clico encima de ellas, después me desaparecen.

    ?Sabéis de algún código que cumpla esa funcionalidad? Yo no lo he encontrado, a lo mejor porqué no sé como buscarlo. Agradecería una respuesta por parte de alguien.

    ?Muchas gracias!

    PS.- You can answer me in english, thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hey there, I don’t know what’s the code you’ve been using, but maybe something like this would help:

    <?php if ( is_page() ) { ?>
    
    <?php
    if($post->post_parent)
    $children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0'); else
    $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
    if ($children) { ?>
    
    <li>
    <h2>
    <?php
    $parent_title = get_the_title($post->post_parent);
    echo $parent_title;
    ?>
    </h2>
    
    <ul>
    <?php echo $children; ?>
    </ul>
    </li>
    
    <?php } } ?>
    Thread Starter albertbarba

    (@albertbarba)

    Hi Julia!

    Thanks for your support. I tried to use this piece of code and it doesn’t work for me. I’ll paste here the code I’m using and now it works, but only with the first level. I would like it works for all the children and for those which has no children.

    <?php
    $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
    if ($children) { ?>
    
    <ul id="parent-menu">
    <?php echo $children; ?>
    
    <?php } ?>
    
    <?php
    if (is_category()) {
    $this_category = get_category($cat);
    if (get_category_children($this_category->cat_ID) != "") {
    echo "<ul id='parent-menu3'>";
    wp_list_categories('orderby=name&show_count=0&title_li=
    &use_desc_for_title=1&child_of='.$this_category->cat_ID);
    echo "";
    }
    }
    ?>

    Can you do something with this code?

    Thanks a lot Julia

    popper

    (@julialasarte)

    This isn’t very pretty, but it does – i think- what you want:

    https://wordpress.pastebin.com/SVF7yq9X

    Thread Starter albertbarba

    (@albertbarba)

    Thank you thank you thank you!!!!!!

    This code really works!!

    I wish you good luck! ??

    Cheers!

    Thread Starter albertbarba

    (@albertbarba)

    Only one thing!

    With the original code, nothing is showed if there is no categories, but now with your code is showing “no categories”. What can I do.

    Hey, this is the last thing I’m asking to you. Sure ??

    popper

    (@julialasarte)

    Thread Starter albertbarba

    (@albertbarba)

    YOU
    ARE
    COMPLETELY
    AWESOME!!

    Thanks Julia!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘?Cómo mostrar siempre todas las categorias hijo navegando en un único padre?’ is closed to new replies.