How do you limit the number of items that show up in a navigation?
If this is a Craft 2 project, unfortunately there's not a super clean way to do that. You'd have to get the last top-level item in the nav you want to show, and add a bunch of conditions in the code to make sure the entry you're outputting isn't after that 5th entry.



{# get the 5th top-level page #}
{% set fifthElement = craft.entries()
    .section('productPages')
    .level(1)
    .nth(4) %}

{# get all the pages #}
{% set ppages = craft.entries()
    .section('productPages')
    .level('&lt;=2')
    .find() %}

{# now display the nav, but only output HTML for entries that are
   within the first 5 top-level entries #}

&lt;ul id="submenu" class="submenu"&gt;
{% nav page in ppages %}
    {% if page.lft &lt; fifthElement.rgt %}
      &lt;li class=“top-level"&gt;
        {{ page.getLink() }}
    {% endif %}
  {% ifchildren %}
    {% if page.lft &lt; fifthElement.rgt %}&lt;ul&gt;{% endif %}
    {% children %}
    {% if page.lft &lt; fifthElement.rgt %}&lt;/ul&gt;{% endif %}
  {% endifchildren %}
    {% if page.lft &lt; fifthElement.rgt %}
      &lt;/li&gt;
    {% endif %}
  {% endnav %}
&lt;/ul&gt;


In Craft 3 it would be quite a bit simpler, though, as you have the power to modify the element query however you want. So we can first get the 5th top-level entry’s rgt value, and then when running our main ppages query, only get the ones whose lft value is less than that 5th entry’s rgt value.

{# get the 5th top-level page #}
{% set fifthElement = craft.entries()
    .section('productPages')
    .level(1)
    .nth(4) %}

{# get all the pages that are within the first 5 top-level pages #}
{% set ppages = craft.entries()
    .section('productPages')
    .level('&lt;=2')
    .andWhere(['&lt;', 'lft', fifthElement.rgt])
    .all() %}

{# now output the navigation normally #}

&lt;ul id="submenu" class="submenu"&gt;
  {% nav page in ppages %}
    &lt;li class=“top-level"&gt;
      {{ page.getLink() }}
  {% ifchildren %}
    &lt;ul&gt;
      {% children %}
    &lt;/ul&gt;
  {% endifchildren %}
    &lt;/li&gt;
  {% endnav %}
&lt;/ul&gt;




If you’re unfamiliar with these lft and rgt values, they are attributes of structured entries, which define their position within the structure, using the “Nested Set” model. The easiest way to think of it is, your structure section is like an XML file, and each of the entries are nodes within it. Each entry has a opening tag and a closing tag on different lines, and lft and rgt are those line numbers.

1 &lt;top_entry&gt;
2   &lt;nested_entry&gt;
3   &lt;/nested_entry&gt;
4 &lt;/top_entry&gt;


So when we do {% if page.lft &lt; fifthElement.rgt %}, we are saying “make sure that this node’s ‘opening tag’ comes before the fifth element’s ‘closing tag’”.