After some extensive Googling I've managed to put together a multi-tiered menu using the wp_list_pages function. It works great everywhere except on the "Not found" page. On that page the code somehow gets it wrong and outputs the first level elements as a subnav/second row, which results in a duplication of the main menu. See code below.
Does anyone have a clue to why this is? And how do I resolve it?
I thought that maybe a custom 404 template would fix it, but when I put a 404.php in my Atahualpa folder it doesn't get used as I read somewhere it would...
The code that goes in header.php looks like this:
PHP Code:
<ul id="nav">
<?php
$exclude_pages = array('nyheter');
$excl_str = array();
foreach( $exclude_pages as $title ) {
$page = get_page_by_title( $title );
$excl_str[] = $page->ID; }
$excl = implode(',', $excl_str);
wp_list_pages('title_li=&depth=1&exclude='.$excl.'');
?>
</ul>
<?php
$parent_id = $post->post_parent;
$parent = get_post($parent_id);
if($post->post_parent){
if($parent->post_parent){
$child = wp_list_pages("depth=1&title_li&child_of=".$parent->post_parent."&echo=0&exclude=".$excl."");
$child2 = wp_list_pages("depth=1&title_li&child_of=".$parent->ID."&echo=0&exclude=".$excl."");
} else {
$child = wp_list_pages("depth=1&title_li&child_of=".$parent_id."&echo=0&exclude=".$excl."");
$child2 = wp_list_pages("depth=1&title_li&child_of=".$post->ID."&echo=0&exclude=".$excl."");
}
} else {
$child = wp_list_pages("depth=1&title_li&child_of=".$post->ID."&echo=0&exclude=".$excl."");
}
if($child){
echo '<ul id="subnav-level-1" class="subnav">'."".$child."".'</ul>';
}
if($child2){
echo '<ul id="subnav-level-2" class="subnav">'."".$child2."".'</ul>';
}
?>