Timber\Menu

Overview

Properties

Name Type Description
depth integer The depth of the menu we are rendering
items array/null Array of Timber\Menu objects you can to iterate through.
id integer The ID of the menu, corresponding to the wp_terms table.
ID integer The ID of the menu, corresponding to the wp_terms table.
term_id integer The ID of the menu, corresponding to the wp_terms table.
name string The name of the menu (ex: Main Navigation).
raw_options array The unfiltered options sent forward via the user in the __construct
title string The name of the menu (ex: Main Navigation).

Methods

Name Type Returns/Description
find_parent_item_in_menu \Timber\MenuItem/bool A menu item. False if no parent was found.
get_items array Array of Timber\MenuItem objects. Empty array if no items could be found.

Class Methods

__construct

__construct( int/string $slug, array $options=array() )

returns: void

Initialize a menu.

Name Type Description
$slug int/string A menu slug, the term ID of the menu, the full name from the admin menu, the slug of theregistered location or nothing. Passing nothing is good if you only have one menu. Timber will grab what it finds.
$options array An array of options, right now only depth is supported

find_parent_item_in_menu

find_parent_item_in_menu( array $menu_items, int $parent_id )

returns: \Timber\MenuItem/bool A menu item. False if no parent was found.

Find a parent menu item in a set of menu items.

Name Type Description
$menu_items array An array of menu items.
$parent_id int The parent ID to look for.

get_items

get_items( )

returns: array Array of Timber\MenuItem objects. Empty array if no items could be found.

Get menu items.

Instead of using this function, you can use the $items property directly to get the items for a menu.

Twig

{% for item in menu.get_items %}
    <a href="{{ item.link }}">{{ item.title }}</a>
{% endfor %}

This class extends \Timber\Core