使用非常简单的自定义walker…
class WPSE_82726_Comma_Walker extends Walker
{
public function walk( $elements, $max_depth )
{
$list = array ();
foreach ( $elements as $item )
$list[] = "<a href=\'$item->url\'>$item->title</a>";
return join( \', \', $list );
}
}
…并按如下方式调用菜单:
wp_nav_menu(
array (
\'theme_location\' => \'your_registered_theme_location\',
\'walker\' => new WPSE_82726_Comma_Walker,
\'items_wrap\' => \'<p class="menu">%3$s</p>\'
)
);
快速高效。:)