Forums

[resolved] Parent Page as heading in wp_list_pages (3 posts)

  1. Malin
    Member
    Posted 5 years ago #

    I want the parent of the subpage to show up as the heading.
    In this code the id of the parent shows up as the heading. How do I get the parent id title instead of the parent id number?

    wp_list_pages('title_li=<h2>' . __("$post->post_parent") . '</h2>&child_of='.$post->post_parent.');

    I also tried <?php the_title('<h2>', '</h2>'); ?> which gives the title... is there a way to make it the "parent-title" instead?

  2. Malin
    Member
    Posted 5 years ago #

    Okay, the problem is solved, here's the code:

    <?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) { ?>

    <div id="rightpadbox">
    <h2>
    <?php
    $parent_title = get_the_title($post->post_parent);
    echo $parent_title;
    ?>
    </h2>
    `

      <?php echo $children; ?>

    </div>
    <?php } ?>

    I got it from a post by "converting2wp", check it out here

  3. isign4jc
    Member
    Posted 5 years ago #

    Awesome! Thanks so much for posting the code for that!!! It worked beautifully on my site.

Topic Closed

This topic has been closed to new replies.

About this Topic