在做中文企業網站主題是,經常需要在側邊欄中顯示菜單,菜單與之間存在母子關係。
目前我的做法是:
所有菜單中使用頁面,設置好頁面的父子關係;
在側邊欄中自動列出當前頁面下的所有子頁面名和鏈接,具體代碼如下:
<?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) { echo '<ul>'; echo $children; echo '</ul>'; } ?>