Tuesday, January 10, 2012

Set limit wp_nav_menu

<?php $pages = wp_nav_menu( array( 'container_class' => 'menu1' ,'menu'=> 'Main Navigation','theme_location' => 'menu1', 'menu_class' => 'dropdown', 'echo' =>false,'container' => false ) );?>
<ul class="dropdown">
<?php
$limit = 5;

$pages_list = preg_replace(array('#^]*>#','#$#'), '', $pages);


$pages_arr = explode("\n", $pages_list);

for($i=0;$i<$limit;$i++){
    echo $pages_arr[$i];
}

?>
</ul>

1 comment:

kingkongstars said...

helo!
Thank's
your code is great but it limits top and subpages as well , in other word toplinks and sublinks are counted alltogether.
How would you count only top links, without touching subpages?

Post a Comment