aldolat
Member
Posted 3 years ago #
Hi, :)
I am using this code (taken and modified from Codex [1]) in my sidebar to display a list of subpages:
<?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 class="boxside">
<h2>Subpages of
<a href="<?php echo (get_permalink($post->post_parent)); ?>" title="Go back to page <?php echo get_the_title($post->post_parent); ?>">
<?php echo get_the_title($post->post_parent); ?>
</a>
</h2>
<ul class="pages">
<?php echo $children; ?>
</ul>
</div>
<?php } ?>
It works very well as I like, but it does not work in pages that use a template. In other words, if I use page.php it works fine; else if I use my-template.php it doesn't.
Do you know why?
[1] http://codex.wordpress.org/wp_list_pages#List_subpages_even_if_on_a_subpage
but it does not work in pages that use a template.
Please describe what doesn't work.
aldolat
Member
Posted 3 years ago #
You're right! Excuse me!
That code displays a subpages menu on my sidebar when you are on a page that has subpages or on a subpage of them (like the codex describes in the link reported above); if a page hasn't subpages, the code doesn't display anything.
The code displays the submenu in all pages, but doesn't display that submenu only in two pages. I tried to understand the reason without success.
Here the link to my blog: http://www.aldolat.it/
The manu page is located at the top of the page.
The two pages that don't display the menu are:
http://www.aldolat.it/archivio/
and
http://www.aldolat.it/archivio/featured/
The subpage menu appears at the top of the sidebar.
Thank you for your kind support. :)
You are welcome!
Can only guess that the archivio pages are using a Page Template that does not have <?php get_sidebar(); ?> in the Template file.
Related
Stepping Into Template Tags
Stepping Into Templates
Template Hierarchy
Good luck.
aldolat
Member
Posted 3 years ago #
Those two pages --like the other single pages-- have <?php get_sidebar(); ?>, otherwise they couldn't display the subpages menu.
You are sure the pages are assigned those page templates?
If so, please paste the code from one of those templates in a pastebin and report the link back here.
aldolat
Member
Posted 3 years ago #
The pages use these templates:
1. Archivio --> archives.php
2. Featured posts --> featured.php
Here are two screenshots of admin panel:
1. Archivio --> http://www.imagebam.com/image/9a004b24325888
2. Featured posts --> http://www.imagebam.com/image/5eaf2b24325941
Here are the two source codes:
1. Archivio --> http://aldolat.pastebin.com/m4b72c119
2. Featured posts --> http://aldolat.pastebin.com/md2a2d9
I have highlighted two lines in them.
aldolat
Member
Posted 3 years ago #
Michael,
seems that I solved the problem. :D
Moving the <?php get_sidebar(); ?> on top of those pages caused the submenu to appear.
I do not understand the reason... it would be interesting to know!
[edit]
I added this line below the <?php get_sidebar(); ?>
<?php $post = $posts[0]; ?>
because in the sidebar I already have a query_posts (to view an excerpt of a random featured article). Otherwise I see the title of that query on sidebar as page title! :)