Support » Fixing WordPress » pull the_content from each child, reproduce on parent page.

  • Resolved george.brooks



    So, I’ve been trying and trying to do this, and it’s just p*ssing me off. I think my main problem is that I don’t understand how to run the Loop at the same time as a foreach.

    So, I’m working on a lab website ( and in the ‘Meet the Lab’ section, I want each person to have an individual page. The template for this takes all sorts of info from the user profile and the avatar to produce the facts of the biography, and then the content actually written on the page makes up the rest.

    That’s the easy part. As you can see, it works pretty well:

    However, I then want to make a summary page (the ‘Meet the Lab’ parent page) which has the same info parts grabbed from the profile (easy, as I just duplicate the code to make it in individual biographies) but then draws the_content from the child page for each person.

    Here’s the code I’m using to generate the ‘Meet the Lab’ page, which is exactly the same as the individuals, apart from in the child pages I use a snippet of code to correctly define $author as the post’s $author, and the child pages also have the_content() in them.

    [Code moderated as per the Forum Rules. Please use the pastebin]

    All I want to do is call the_content from the child page for that author. The solution has to be dynamic – so I can’t just specify the page ID, it needs to find it based on the the author and the fact it’s getting it from one of its children.

    Please help people, I know this is simple, but I just can’t get it to play ball.


    George B.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Code can be found on previous post. They’re similar posts, I know, but I’ve reframed the problem to make it a lot more straightforward.

    See code here:

    Moderator keesiemeijer


    I still don’t get what you want.

    I want each person to have an individual page

    this works.

    All I want to do is call the_content from the child page for that author.

    Did my code not work this way? explain what has to be altered? Or do you want additional functionality?

    but I’m going to try it a different way.

    is not really explaining what was wrong with the code I gave you.
    Reframing the question didn’t make it a lot more straightforward to what you want.

    Put all the code you have for the parent page in the pastebin and give us a link to it.

    Hi keesiemeijer,

    I just read back over both of my forum posts for this problem, and two things have become apparent:

    1) They appear far more similar than I realised
    2) I sound very rude and ungrateful.

    The first is probably true. The second definitely isn’t. I appreciate your help, and so I am sorry. Clearly this is what happens when I try to code last thing at night!

    OK, so I’ve put the current page template code that the Meet the Lab parent page uses here: . I’ve highlighted the ‘description’ line which currently comes from the profile page’s biographical info box for each user.

    Here is the the page template code for the child pages (those containing info for just one user) :

    I did try to use your code, but it brought up post content from the news section, not the child page content.

    Moderator keesiemeijer


    I did try to use your code, but it brought up post content from the news section, not the child page content.

    did you change the Page ID in <?php query_posts('post_parent=2'); ?>?

    I will try to do it with a get_pages with the code in the pastebin.

    I did try using the post_parent= as the number of the page (taken from the link shown when you try to edit it from control panel, for example) and also by defining a variable either as a fixed value or the_ID for the page, but it made no difference.

    I think get_pages is the answer, but I just don’t understand how to incorporate it into my current page.

    Thanks again,


    Moderator keesiemeijer


    Try it with this parent page

    Moderator keesiemeijer


    Ok I did some further testing and if the author was not a parent page it did not work. I amended the code here: parent page

    This code will get the last post (post content) written by an author.
    change the ID in $authorpages = get_pages('child_of=65&authors='.$name);


    That’s just what I’ve done!

    This seems to work now. I’ve also enclosed the avatar in a div to format it.

    Cheers for the help!

    The final product is here:

    And not too shabby, if I do say so myself.

    Moderator keesiemeijer


    You’re welcome. Not too shabby at all! For sheeeeezy!

    Right then. I’ve got another little problem.

    I would like to curtail the content that’s been pulled, and have a ‘Read More…’ link to the child page(s) included at the end of each users’ section. This way, the list will be a very brief overview, and if they’re interested, viewers can read more on the child page.

    Clearly I’m not going to be able to use a <!–more–> tag, as this isn’t really the_content, it’s just a variable. Anyway, I’ve tried it. Doesn’t work.

    I did find this suggestion here:

    Which is elegant is concept, but worthless in execution. I’ve tried using this and getting the permalink based on the page ID from the array that the post content comes from (so it’s linking to the right page) but no luck. It just doesn’t trim the text!

    Any suggestions?

    Moderator keesiemeijer


    With this alteration you can use the more tag

      $content_more = false;
      $name = get_the_author_meta('user_nicename', $author->user_id);
      $authorpages = get_pages('child_of=85&authors='.$name);
      if(preg_match('/'.preg_quote('<!--more-->', '/') .'/', $authorpages[0]->post_content)) {
        $newcontent = get_extended($authorpages[0]->post_content);
        $content = $newcontent['main'];
        $content_more = true;
      } else { $content = $authorpages[0]->post_content; }
      $content = apply_filters('the_content', $content);
      echo $content;
      <?php if($content_more) : ?>
      <a href="<?php echo get_permalink($authorpages[0]->ID); ?>" title="<?php echo 'Read more about: '  . $authorpages[0]->post_title; ?>" >Read more</a>
      <?php endif; ?>


    This works fantastically well.

    Thank you SO MUCH for your help, you’ve been a wonder.

    That’s all my questions answered!


    George B.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘pull the_content from each child, reproduce on parent page.’ is closed to new replies.