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>

Comments

  1. 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?

    ReplyDelete

Post a Comment

Popular posts from this blog

PHP: Date Difference for PHP 5.2

display the_content with setup_postdata

Custom OpenCart 2.3.0.2 theme