Getting started – Limit and Offset
-
NOTE: This documentation is also included in the /documentation/ folder with your plugin download, and is easier to read in that format.
LIMIT AND OFFSET
Often website designs call for a menu to be split up into multiple columns, or rows. Such as a multi-column footer sitemap. WP Nav Plus provides the capabilities you need to quickly build these custom menu layouts using Limit and Offset.
Build your custom menu layout in one of two ways:
Easy Method (Widget)
The easiest way to get up and running quickly with WP Nav Plus is to make use of the widget. In this section I will show you how to implement a basic divided menu using the WP Nav Plus widget.
- Login to your WordPress Admin page (usually https://yourdomain.com/wp-admin)
- Navigate to the Widgets screen (Under “Appearance”)
- Notice the new widget called “WP Nav Plus” (pictured below)<br />
- Click and drag this widget into the desired sidebar placement (pictured below). NOTE: My sidebar is called “Primary Sidebar”, your sidebar may be named differently. Please see your theme documentation for additional details about your sidebars.<br />
- Specify your menu “limit” and/or your menu “offset” as needed to reach your desired output.
- Use multiple widgets as needed to complete your custom layout.
Advanced Method (Function)
The documentation above has focused on using the WP Nav Plus widget as the easiest way to get started with WP Nav Plus. However for advanced users who want more control over the output of their menu, WP Nav Plus can be used with the built in WordPress wp_nav_menu function
WP Nav Plus adds two arguments to the wp_nav_menu function for use with custom menu layouts.
- option: limit
- type: int
- default: false
- desctiption: Limit the number of top-level menu items to return when displaying your menu. Given a menu with 10 top-level items in it, and a limit set to 5, only the first 5 top-level items would be displayed. All menu children belonging to the displayed top-level menu items will be left alone.
- option: offset
- type: int
- default: false
- desctiption: Offset or “skip” a set number of top-level menu items when displaying your menu. Given a menu with 10 top-level items in it, and an offset of 3, only the last 7 top-level menu items would be displayed.
Basic Example: (assumes a menu iwth 10 items in it)
wp_nav_menu( array( 'theme_location' => 'my_menu', 'limit' => 5, 'offset' => 2 ) );
The above example would create a menu which displayed only 5 menu items, skipping over the first two menu items, showing the next five, and then nothing after those five.
- The topic ‘Getting started – Limit and Offset’ is closed to new replies.