这是一个问题I的后续问题posted previously,
好的,我试图输出的html代码与前面的问题相同-here:
当前输出的html如下:
<div id="nav">
<ul id="drop-nav">
<li><a href="#">About Us</a>
<div class="subnav">
<div class="subnavTop">
<ul class="subnavContent">
<li>
<dl>
<dd><a href="#">Child of About</a></dd> <!-- Child Item | Depth = 1 -->
<dd><a href="#">Grandchild of About</a></dd> <!-- GrandChild Item | Depth = 2 -->
</dl>
</li>
</ul>
</div>
</div>
</li>
<li><a href="#">Talk to us</a></li>
</ul>
<br style="clear: left" />
</div>
这是我在header中使用的代码。php生成html/菜单项:
<div id="nav">
<ul id="drop-nav">
<?php
// Query the database for all top-level page IDs, and store them in the $menuPages array under the [ID] sub-array
$menuPages = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_parent=0 AND post_type=\'page\' AND post_status=\'publish\' ORDER BY menu_order ASC");
// For each element in the $menuPages array, get the value from the [ID]-subarray to create the top-level menu and it\'s children
foreach($menuPages as $menuItem){
$menuItemTitle = get_the_title($menuItem->ID);
$menuItemClass = strtolower(trim($menuItemTitle));
$menuItemClass = preg_replace(\'/[^a-z0-9-]/\', \'-\', $menuItemClass);
$menuItemClass = preg_replace(\'/-+/\', "-", $menuItemClass);
$menuItemPermalink = get_permalink($menuItem->ID);
if (isset($menuItemTitle) && $menuItemTitle != \'Home\'){
_e(\'<li class="\'.$menuItemClass.\'">\'.PHP_EOL);
_e(\'<a href="\'.$menuItemPermalink.\'">\'.$menuItemTitle.\'</a>\'.PHP_EOL);
// Run wp_list_pages to fetch any children, and put the HTML <LI> list results into $menuItemChildren as a string
$menuItemChildren = wp_list_pages(\'title_li=&echo=0&sort_column=menu_order&child_of=\'.$menuItem->ID);
$menuItemChildren = preg_replace(\'%<li class=".*">%U\', \'\', $menuItemChildren);
$menuItemChildren = str_replace(\'</li>\', \'\', $menuItemChildren);
$menuItemChildren = str_replace(\'<a\', \'<dd><a\', $menuItemChildren);
$menuItemChildren = str_replace(\'</a>\', \'</a></dd>\', $menuItemChildren);
$menuItemChildren = str_replace(\'<ul class=\\\'children\\\'>\', \'\', $menuItemChildren);
$menuItemChildren = str_replace(\'</ul>\', \'\', $menuItemChildren);
// If results were returned, $menuItemChildren is now a string with HTML in it, so create a drop-down and echo out the HTML
if($menuItemChildren){
_e(\'<div class="subnav">\'.PHP_EOL);
_e(\'<div class="subnavTop">\'.PHP_EOL);
_e(\'<ul class="subnavContent">\'.PHP_EOL);
_e(\'<li>\'.PHP_EOL);
echo \'<dl>\' .$menuItemChildren. \'</dl>\' . PHP_EOL;
_e(\'</li>\'.PHP_EOL);
_e(\'</ul>\'.PHP_EOL);
_e(\'</div>\'.PHP_EOL);
_e(\'</div>\'.PHP_EOL);
}
_e(\'</li>\'.PHP_EOL);
}
}
?>
</ul>
<br style="clear: left" />
</div>
我知道这可能是一种非常糟糕的方式,但它似乎可以完成大部分工作。
现在唯一值得一提的是,将级别/深度1上的子项/子页从“dd”更改为“dt”,将下面的任何页面都保留为dd。我想我需要一些代码,将第一个项/子项标记为“dt”,然后将其他所有项/子项标记为“dd”,但我一生都搞不清楚。
希望这是有意义的,并非常感谢任何帮助,S。
(我已经研究了Walker类方法:()