Felipe Skroski
  • Home
  • About
  • Portfolio
  • Blog
  • FMG Plugin
  • Contact

3 Level navigation menu in wordpress

Posted on April 14, 2008 under blog

Is such a easy thing doing 2 levels menu, but when you need more than this things can get really complicated. In the hope that someone out there could have had the same problem as me I started googling, read forums and etc and I didn’t found any solution without using plugins.

So I end up doing my own code to do this and I hope can be useful for somebody:

<?php
$parent_id = $post->post_parent;
$parent = get_post($parent_id);
if($parent->post_parent){
$top_level_id = $parent->post_parent;
}else if($post->post_parent){
$top_level_id = $post->post_parent;
}else{
$top_level_id = $post->ID;
}
if($parent->post_parent){
$children = wp_list_pages("title_li=&child_of=".$parent->post_parent."&echo=0");
$my_id = $parent->post_parent;
}else if($post->post_parent){
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
$my_id = $post->post_parent;
}else{
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
$my_id = $post->post_parent;
}
if ($children) {
$post_id_7 = get_post($my_id);
$title = $post_id_7->ID;
?>
<div id="submenu" class="sub_id_<?php echo $title;?>">
<ul>
<?php echo $children; ?>
</ul>
</div>
<?php } ?>

No Comment

Posting your comment.

RSS | email: me@felipesk.com | phone: +64 021 0245 6465
| Clicky Web Analytics