WordPress.org

Ready to get started?Download WordPress

Forums

display sub-page, even if on a sub-sub-page (5 posts)

  1. Martensen
    Member
    Posted 6 years ago #

    if someone clicks on a parent page, the list of sub-pages should appear above it. i managed to do that by using the code i found here in the forums and some css.

    so this is my current code in the sidebar:

    <ul>
    <?php
    if($post->post_parent)
    $children = wp_list_pages("title_li=<h2>Sub Pages</h2>&child_of=".$post->post_parent."&echo=0"); else
    $children = wp_list_pages("title_li=<h2>Sub Pages</h2>&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <ul>
    <?php echo $children; ?>
    </ul>
    <?php } ?>
    <?php wp_list_pages('sort_column=ID&depth=1&title_li=<h2>Pages</h2>' ); ?>
    </ul>

    example: http://ads-rantum.beachlevel.com/unser-haus/

    this shows the sub-pages (called ”extra seiten“ in the example) above the list of the parent pages (called ”seiten“ in the example). but when i click on a sub-sub-page now, the first sub-page disappears from the list. same with clicking on a sub-sub-sub-page, now the sub-sub-page disappears as well.

    now i need something, so the parent of a sub will be listed, even if that parent is a sub itself (i call it a faked parent for now).

    anyone with an idea, my fellow wp users? ;)

  2. Martensen
    Member
    Posted 6 years ago #

    Well, i saw that there are some solutions already whipped up by Code Overlord Kafkaesqui, but since i don’t speak fluent php, i kinda need my own code modified and ready to be pasted, since i have no clue where to start and end my copy/paste process.

    So a big SORRY for that in advance.

    Here is my complete left sidebar code:

    <div id="sidebar_left">
    		<ul>
    			<?php
    			if($post->post_parent)
    			$children = wp_list_pages("title_li=<h2>Extra Seiten</h2>&child_of=".$post->post_parent."&echo=0"); else
    			$children = wp_list_pages("title_li=<h2>Extra Seiten</h2>&child_of=".$post->ID."&echo=0");
    			if ($children) { ?>
    			<ul>
    			<?php echo $children; ?>
    			</ul>
    			<?php } ?>
    			<?php wp_list_pages('exclude=51,64,67&sort_column=ID&depth=1&title_li=<h2>Seiten</h2>' ); ?>
    		</ul>
    </div>

    Site url again: http://ads-rantum.beachlevel.com/unser-haus/

  3. Martensen
    Member
    Posted 6 years ago #

    I had another idea.

    Instead of using the fixed title_li=<h2>Fixed title</h2>
    i use as headline for the subpage list, i could use something
    dynamic that displays the parents title.

    I mean like this:

    wp_list_pages("title_li=__TITLE_OF_PARENT_PAGE__&child_of=".$post->post_parent."&echo=0")

    Is that possible somehow?

  4. anabelle
    Member
    Posted 6 years ago #

    please let it be possible!! im looking for this too

  5. Martensen
    Member
    Posted 6 years ago #

    Well, the closest i found was the breadcrumb plugin.

Topic Closed

This topic has been closed to new replies.

About this Topic