• Resolved enricolino

    (@enricolino)


    Hello there

    I have been searching for the right solution but I had no luck yet. I am trying to display a list of grandchild pages in a child page, but I just don’t seem to be able to. My parent page is “Fungal species” and its child-pages are two: determined and undetermined (see https://www.neotropicalfungi.com/wp/). I would like to have an alphabetical list on each child page, showing all the names of the mushrooms, each one linking to its own page with pictures and description etc. (like I manually did here: https://www.neotropicalfungi.com/wp/fungal-species/determined/). I already created a page-template and added some php code to functions.php, but this works with child pages only (see https://www.neotropicalfungi.com/wp/provalista/). Can anyone please help? I hope I explained myself clearly.

    Thanks in advance

    Ciao

    Enrico

    • This topic was modified 7 years, 4 months ago by enricolino.
Viewing 5 replies - 16 through 20 (of 20 total)
  • Thread Starter enricolino

    (@enricolino)

    Hello again Konstantinos,

    thanks for the explanation and the effort; I really appreciate it! I didn’t explained myself properly, sorry. I surely don’t want to change the whole pages of my website, you are absolutely right, but I used the suggested to beginners, to create page templates. They usually tell you to take the page.php file as a start and edit it adding some code. This is why I was trying to “mix” the code you gave to me, with the one of the standard pages of the theme I used and I was almost done, but just ALMOST :D…. The result was a page with the same look as others, but with the list of links (grandchild pages) over the title :D. I tried a few times to put it elsewhere and have it sorted, but I failed! I will try again now and I hope to have success…. Enjoy your family and have a lovely Sunday!

    Thanks again

    Ciao

    Enrico

    Thread Starter enricolino

    (@enricolino)

    This is the result of my experiment :)…. As you can see, I’m almost there ^_^…

    https://www.neotropicalfungi.com/wp/fungal-species/determined/

    Enrico

    Hey Enrico!

    So I got the template you are using and just out of a quick research I managed to fix you this up.

    How to get it working. Under your child theme create an enrico.php and paste the following code

    
    <?php
    // Template Name: Custom List
    get_header();
    $pages = get_posts(array(
        'post_type' => 'page',
        'orderby' => 'title',
        'order' => 'ASC',
        'posts_per_page' => -1
    ));
    global $post;
    ?>
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main" <?php hybrid_attr( 'content' ); ?>>
    
            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?> <?php hybrid_attr( 'post' ); ?>>
    
                    <header class="entry-header">
                        <?php the_title( '<h1 class="entry-title" ' . hybrid_get_attr( 'entry-title' ) . '>', '</h1>' ); ?>
                    </header><!-- .entry-header -->
    
                    <?php get_template_part( 'entry', 'meta' ); // Loads the entry-meta.php template. ?>
    
                    <div class="entry-content" <?php hybrid_attr( 'entry-content' ); ?>>
                            <ul>
                                <?php $children = get_page_children($post->ID, $pages); ?>
                                <ul>
                                    <?php foreach ($children as $child): ?>
                                        <?php if ($child->post_parent == $post->ID): ?>
                                            <li>
                                                <a href="<?php echo get_permalink($child->ID); ?>"><?php echo $child->post_title; ?></a>
                                                <?php $granchildren = get_page_children($child->ID, $pages); ?>
                                                <ul>
                                                    <?php foreach ($granchildren as $grandchild): ?>
                                                        <li><a href="<?php echo get_permalink($grandchild->ID); ?>"><?php echo $grandchild->post_title; ?></a></li>
                                                    <?php endforeach; ?>
                                                </ul>
                                            </li>
                                        <?php endif; ?>
                                    <?php endforeach; ?>
                                </ul>
                                </li>
                            </ul>
                    </div><!-- .entry-content -->
    
            </article><!-- #post-## -->
    
        </main>
    </div>
    <?php
    get_footer();
    ?>
    

    After that go to the pages that you want to view as ‘lists’ and select ‘Custom List’ from the template on the right.

    That’s what I did at least and everything is in order. Now again I don’t know exactly what else you have changed so you might have to do adjustments.

    Hope this helps out!

    Best regards,
    Konstantinos

    Thread Starter enricolino

    (@enricolino)

    You are really great, this worked perfectly, THANKS a lot :)!!!!! If you ever happen to come to Italy, please let me know so we can drink a beer together ^_^….

    Cheers

    Enrico

    Hahah, awesome will do friend!

    Glad I could help ??

    If you need anything else feel free to ask in a new topic.

    Ciao!

    Best regards,
    Konstantinos

Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘Display grandchild pages on a child page’ is closed to new replies.