Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6920743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:11:13+00:00 2026-05-27T10:11:13+00:00

I have created a function within my themes functions.php file in order to persist

  • 0

I have created a function within my themes functions.php file in order to persist a list of child pages from the level of a parent page while navigating deeper within the hierarchy.
My issue is that when I call the function within the page.php theme file I dont get anything back.

functions.php:

function get_top_parent_children($the_id,$start = 0,$walk = null){

    $current_post = get_post($the_id);
    $walk[] = $current_post;

    if($current_post->post_parent){
        get_top_parent_children($current_post->post_parent,$start,$walk);
    } else {
        $output = array_reverse($walk);
        return get_children($output[$start]->ID);
    }
}

page.php:

<?php get_header(); ?>
<div id="primary" class="clearfix">

    <div id="content">
        <?php the_post(); ?>
        <?php $children = get_top_parent_children($id,1); ?>
        <?php if ( $children ) { ?>
            <section id="post-topic">
                <h2><?php the_title() ?> Topics</h2>
                <ul class="clearfix">
                    <?php foreach( $children as $child){ ?>
                        <li>
                            <a href="<?php echo get_permalink($child->ID) ?>"> <?php echo child->post_title ?> </a>
                        </li>
                    <?php }; ?>
                </ul>
            </section>
        <?php }; ?>
        <?php get_template_part( 'content', 'page' ); ?>
    </div>
    <aside>
        <?php dynamic_sidebar('Page Sidebar'); ?> 
    </aside>
</div>
<?php get_footer(); ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:11:14+00:00Added an answer on May 27, 2026 at 10:11 am

    I guess you forgot the second return. You have an if with two code paths, but only return a value in the last one. You need:

    if($current_post->post_parent){
        return get_top_parent_children(...);
       # ^^^^
    } else {
        return get_children(...);
    }
    

    Your function is (recursively) calling itself when that condition matches. But you still need to instruct PHP that it should pass on the value to the outer call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem whereby, i have created a user defined function within php.
I have created a function in PHP that calls a webservice and parses through
i have created a module with this among others this function in it: <?php
I have created a custom ArrayAdapter to display data within ListView items from an
I have created a class called ShortestTime. I have some functions within it that
In Python, if I have a child function within a parent function, is the
I have created a function that takes a SQL command and produces output that
I have created a function outside of $(document).ready() , but am still using jQuery
in my data layer class I have created a function to manually refresh the
Hey, so I have created a function to check the DB for unique entries,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.