WordPress.org

Forums

Loop with Parent and Child page content (2 posts)

  1. katart17
    Member
    Posted 4 years ago #

    I'm trying to do the following functions and need a little help.

    I want to display a list of Pages with Titles and Content. Some Pages have children. The default loop will display a list of all Pages within their own unique DIV. If a Page has Children, can I wrap the Parent Page and its Children within their own unique DIV?

    Here is the structure I'm looking for:

    <div>
      <div><h2>Parent Title One</h2><p>Parent Content One</p></div>
      <div><h3>Child Title One</h3><p>Child Content One</p></div>
      <div><h3>Child Title Two</h3><p>Child Content Two</p></div>
      <div><h3>Child Title Three</h3><p>Child Content Three</p></div>
    </div>
    <div>
      <div><h2>Parent Title Two</h2><p>Parent Content Two</p></div>
      <div><h3>Child Title One</h3><p>Child Content One</p></div>
      <div><h3>Child Title Two</h3><p>Child Content Two</p></div>
      <div><h3>Child Title Three</h3><p>Child Content Three</p></div>
    </div>
    <div>
      <div><h2>Non-Parent Title</h2><p>Non-Parent Content</p></div>
    </div>

    Is this possible within one Loop?

  2. alchymyth
    Forum Moderator
    Posted 4 years ago #

    i would try and use two nested loops; main loop to get pages top level only; foreach of these top level pages, do a loop getting the child pages of each particular parent page.

    http://codex.wordpress.org/Function_Reference/get_pages

Topic Closed

This topic has been closed to new replies.

About this Topic