PHPackages                             livy/climber - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. livy/climber

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

livy/climber
============

An alternative to WordPress's Walker system for navigational menus.

0.2.5(6y ago)484372[3 issues](https://github.com/alwaysblank/climber/issues)MITPHPPHP &gt;=7.1

Since Jan 26Pushed 6y ago4 watchersCompare

[ Source](https://github.com/alwaysblank/climber)[ Packagist](https://packagist.org/packages/livy/climber)[ RSS](/packages/livy-climber/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (5)Versions (7)Used By (0)

🧗 Climber
=========

[](#-climber)

### Why [walk](https://codex.wordpress.org/Class_Reference/Walker) when you can climb?

[](#why-walk-when-you-can-climb)

An alternative to WordPress's built-in Nav\_Walker, 🧗 Climber creates a more reasonable data structure, which can be interacted with directly or used to generate the HTML for a navigation menu.

[![Build Status](https://camo.githubusercontent.com/99a06914fcc067b3d3fdcc65d0ff6326f426ccbd47a36404a9091ff5e10b23ce/68747470733a2f2f7472617669732d63692e6f72672f616c77617973626c616e6b2f636c696d6265722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/alwaysblank/climber)

#### ☠️ Currently in Development ☠️

[](#️-currently-in-development-️)

#### ⚡ Probably not ready for production ⚡

[](#-probably-not-ready-for-production-)

Usage
-----

[](#usage)

The simplest implementation of 🧗 Climber looks like this:

```
use Livy\Climber;

echo new Climber(
  new Tree(
    new Spotter\WordPress(wp_get_nav_menu_items($menuID))
  )
);

//
//
//        ...etc
```

...Maybe not quite so simple. There will be convenience functions eventually!

This document doesn't detail all the methods and ways of interaction with 🧗 Climber—only the ones you're most likely to use. The methods themselves are heavily documented inline, so feel free to dive into the code if you're curious how something works.

How Does It Work?
-----------------

[](#how-does-it-work)

🧗 Climber has three basic components that it needs to work:

- Spotter
- Tree
- Climber

**Spotter** allows for 🧗 Climber to be platform agnostic: While it ships with a WordPress Spotter, you can add whatever Spotters you like to collect and process data. The Spotter's job is to return data in the format that Tree expects.

**Tree** processes the data recieved from Spotter and implements several methods that can be used to quickly and easily interact with the data it contains. Its organization allows Climber to quickly find the things it needs to generate a navigation menu.

**Climber** collects a Tree and returns a properly-constructed navigation menu in HTML.

Generally, you'll only be interacting directly with Climber, but you can easily extend or modify the other components to suit your needs—or use them to modify your data.

Show Me
-------

[](#show-me)

The **Usage** section at the top illustrates the simplest version, which will return a simple menu. In most situations, though, you'll want to tell the menu what page you're on (so it can highlight that section). Or you might want to hook into some part of the process to add or modify elements, CSS classes, or HTML attributes.

```
/**
 * Instantiate our Climber, and tell it where we are.
 */
$Climber = new Climber(
  new Tree(new Spotter\WordPress(wp_get_nav_menu_items($menuID))),
  get_permalink(get_the_ID()))   // This returns the URL for the current page.
);

/**
 * Open all links in a new window.
 */
$Climber->hook(
  'link',
  function ($data) {
    $data['attrs'][] = ['target', '_blank'];
    return $data;
  }
);

/**
 * Put the link after the submenu, instead of before.
 */
$Climber->hook(
  'itemOutput',
  function($data) {
    $data['format'] = '%2$s%1$s';
    return $data;
  }
);

/**
 * Print out our menu
 */
echo $Climber;
```

The `Climber` object will return an HTML menu if treated as a string. Handy!

Hooks
-----

[](#hooks)

In order to allow you to modify the content and behavior of the menu without having to extend the classes, Climber exposes several hooks. Each hook provides a single variable—`$data`—to whatever function is hooked to them. The content of that variable depends on the hook you attach it to. Generally, it is an array with keyed values.

Any function that is passed to a hook **must return something similar to the `$data` it recieved**. Otherwise things will break. See the **Show Me** section of this document, or the contents of `Climber::__construct()` for examples of how to properly construct hooks.

### `top`

[](#top)

This is the 'top' level of the navigation menu: The `` element. The array it provides includes:

- `class` - *string* The CSS class(es) for this element.
- `attrs` - *array* An array of HTML attributes for this element.
- `tree` - *Tree* The Tree instance used for this menu.
- `element` - *string* Format for `sprintf`, to be used in element generation.
- `echo` - *boolean* Whether or not `Tree::element()` should echo the menu. Very few reasons to change this.

### `menu`

[](#menu)

This hook is run for each submenu. If you want to target a *particular* submenu, you'll need to run some sort of test in your passed function to target it. The array it provides includes:

- `class` - *string* The CSS class(es) for this element.
- `attrs` - *array* An array of HTML attributes for this element.
- `level` - *integer* The current depth of this menu. Probably don't change it.
- `element` - *string* Format for `sprintf`, to be used in element generation.
- `bud` - *array* A full leaf, with all leaf data.

### `item`

[](#item)

An individual `` inside a ``. Will ultimately contain a link to a part of your site, and possibly a submenu. The array it provides includes:

- `class` - *string* The CSS class(es) for this element.
- `attrs` - *array* An array of HTML attributes for this element.
- `element` - *string* Format for `sprintf`, to be used in element generation.
- `bud` - *array* A full leaf, with all leaf data.

### `itemOutput`

[](#itemoutput)

This describes the actual *content* of `item`. It can be used to add new things to an `item` (i.e. a `` to open a submenu) or to modify the order of the things appearing in the `item`. The array it provides includes:

- `format` - *string* A formatting string to be used in `vsprintf()`.
- `args` - *array* An array of values that will be passed to `vsprintf()`. Their order is important, because it corresponds to the `format`.

### `link`

[](#link)

This is a link element in an `item`. The array it provides includes:

- `link` - *string* The URL this link goes to.
- `class` - *string* The CSS class(es) for this element.
- `attrs` - *array* An array of HTML attributes for this element.
- `element` - *string* Format for `sprintf`, to be used in element generation.
- `content` - *string* The content of the link element. Usually the name of whatever it links to, i.e. "About".

Settings
--------

[](#settings)

These settings will be applies to all elements of their type, so they can be useful for setting styling or behavior across your menu. The built-in classes are formatted strings. You can change them all with one line by modifying `baseClass`. You can also override them completely, if you wish.

NameTypeDefault`baseClass`string'simpleMenu'`topClass`string'%s'`menuClass`string'%s\_\_menu'`itemClass`string'%s\_\_item'`linkClass`string'%s\_\_link'`topAttr`array`[]``menuAttr`array`[]``itemAttr`array`[]``linkAttr`array`[]`You can override or set Climber-wide properties for element classes and attributes. Doing so is very simple:

```
// For string-type properties...
$Climber->topClass = 'newMenuClass';

// For array-type properties...
$Climber->topAttrs = ['target', '_blank'];
```

Keep in mind:

- String-type properties are **overriden**.
- Array-type properties are **appended**.

This means that if you want to supplement the existing classes, you would do the following:

```
$Climber->topClass .= ' newMenuClass';

//  ...
```

You can override and remove array-type property entries as well:

```
// override
$Climber->topAttr = ['data-star', 'wars'];
$Climber->topAttr = ['data-star', 'trek'];

//  ...

// remove
$Climber->topAttr = ['data-star', 'wars'];
$Climber->topAttr = ['data-star', false];

// ...
```

That's Too Complicated
----------------------

[](#thats-too-complicated)

I agree! Fortunately there are some nice, clean, convenience functions to help do what you want without filling your code up with all those Classes and stuff.

*(This list will expand as necessary. If you think there should be a function here that isn't here, open an issue or submit a PR to add it!)*

All conveninece functions begin with `pulley__`. They follow a convention (borrowed from WordPress): Functions named `get_something` will return a value, while functions simply named `something` will echo that value. For this reason, these functions often come in pairs. If they don't, it's probably because the `get_` version returns something that can't be echoed.

### General

[](#general)

These functions will work in any context, but they require you to pass a valid Spotter.

#### pulley\_\_get\_menu()

[](#pulley__get_menu)

```
pulley__get_menu(
  Spotter   $Spotter,
  string    $currentUrl = null
)
```

##### Arguments

[](#arguments)

- **$Spotter** - *Spotter*An instance of `Spotter` that applies to the context you're calling this in.
- **$currentUrl** - *string*The URL you're currently act, for activating the correct Tree branch. Default: `null`.

##### Returns

[](#returns)

*Climber | false* A Climber object if successful, boolean `false` otherwise.

\_

#### pulley\_\_menu()

[](#pulley__menu)

```
pulley__menu(
  Spotter    $Spotter,
  string     $currentUrl = null
)
```

The same as `pulley__get_menu()`, except that this will echo the menu automatically.

##### Arguments

[](#arguments-1)

- **$Spotter** - *Spotter*An instance of `Spotter` that applies to the context you're calling this in.
- **$currentUrl** - *string*The URL you're currently act, for activating the correct Tree branch. Default: `null`.

##### Returns

[](#returns-1)

*string | false* HTML string of the menu if successful, boolean `false`otherwise.

### WordPress

[](#wordpress)

These functions will only work with WordPress (in fact, Climber will only load them if it believes it is being used in a WordPress context). Because Climber comes packaged with a WordPress Spotter, there's no need to manually pass in a Spotter!

#### pulley\_\_wp\_get\_menu()

[](#pulley__wp_get_menu)

```
pulley__wp_get_menu(
  int|string|WP_Term     $menu,
  string                 $currentUrl = null
)
```

Returns a `Climber` for the `$menu` passed to it.

##### Arguments

[](#arguments-2)

- **$menu** - *int|string|WP\_Term*The value of `$menu` can a menu ID, slug, name, or object. More specifically, it can be any value that [`wp_get_nav_menu_items()`](https://developer.wordpress.org/reference/functions/wp_get_nav_menu_items/)would accept as a menu identifier.
- **$currentUrl** - *string*The URL you're currently act, for activating the correct Tree branch. Default: `null`.

##### Returns

[](#returns-2)

*Climber | false* A Climber object if successful, boolean `false` otherwise.

#### pulley\_\_wp\_menu()

[](#pulley__wp_menu)

```
pulley__wp_menu(
  int|string|WP_Term     $menu,
  string                 $currentUrl = null
)
```

Echoing version of `pully__wp_get_menu()`.

##### Arguments

[](#arguments-3)

- **$menu** - *int|string|WP\_Term*The value of `$menu` can a menu ID, slug, name, or object. More specifically, it can be any value that [`wp_get_nav_menu_items()`](https://developer.wordpress.org/reference/functions/wp_get_nav_menu_items/)would accept as a menu identifier.
- **$currentUrl** - *string*The URL you're currently act, for activating the correct Tree branch. Default: `null`.

##### Returns

[](#returns-3)

*string | false* HTML string of the menu if successful, boolean `false`otherwise.

#### pulley\_\_wp\_get\_menu\_by\_location()

[](#pulley__wp_get_menu_by_location)

```
function pulley__wp_get_menu_by_location(
    string    $location,
    string    $currentUrl = null
)
```

Get a menu based on its location.

##### Arguments

[](#arguments-4)

- **$location** - *string*The name of a $location, as defined in as defined in [`register_nav_menus()`](https://codex.wordpress.org/Function_Reference/register_nav_menus).
- **$currentUrl** - *string*The URL you're currently act, for activating the correct Tree branch. Default: `null`.

##### Returns

[](#returns-4)

*Climber | false* A Climber object if successful, boolean `false` otherwise.

#### pulley\_\_wp\_menu\_by\_location()

[](#pulley__wp_menu_by_location)

```
function pulley__wp_menu_by_location(
    string    $location,
    string    $currentUrl = null
)
```

Same as `pulley__wp_get_menu_by_location()`, just echoes.

##### Arguments

[](#arguments-5)

- **$location** - *string*The name of a $location, as defined in as defined in [`register_nav_menus()`](https://codex.wordpress.org/Function_Reference/register_nav_menus).
- **$currentUrl** - *string*The URL you're currently act, for activating the correct Tree branch. Default: `null`.

##### Returns

[](#returns-5)

*string | false* HTML string of the menu if successful, boolean `false`otherwise.

That's Not Complicated Enough
-----------------------------

[](#thats-not-complicated-enough)

All right, fair. Maybe you need something we haven't covered here: Maybe the menu you're passing to Climber only includes the top level of your site, but you want parent items to still be highlighted when their children are being visited. Since Climber is (by design) ignorant of your site's internal organization, it doesn't directly support this: Climber is only aware of the things its aware of.

You can, however, use a bit of logic to tell Climber what it should consider "active".

### Set Current URL

[](#set-current-url)

The most common usage of Climber involves passing a URL to it on instantiation—either with the class directly, or through one of the helper functions. In either case, internally Climber is using the same method to activate the current URL, and it's a method you can use too!

`Climber::setCurrentUrl()` can be used to pass a URL directly to Climber. Climber will then look for a leaf (or leaves) that point to that URL, and mark them as "active" (if you have a multi-level menu, it will also mark their ancestors as well). Using it is very simple:

```
$Climber = new Climber(
  new Tree(new Spotter\WordPress(wp_get_nav_menu_items($menuID)))
);
$Climber->setCurrentURL(get_permalink(get_the_ID())); // Now this is the current URL!
```

If the Climber you're working with doesn't have that URL, it will do nothing.

It is also worth noting that Climber does not assume there can be only one active leaf: Running `setCurrentUrl()` does not remove previously active leaves.

Access to `setCurrentUrl()` means that with some elbow grease, you can make Climber think you're on any page you like! Unfortunately, if you need to do this with a large number of URLs, `setCurrentUrl()` starts get a little less useful.

That's why there's another way!

### Surveyor

[](#surveyor)

The Surveyor class provides you with a simple way of writing lookups for URL patterns that you want to match particular URLs in Climber. It uses an array of regular expressions to determine what URLs match what.

To use Surveyor, instantiate it with an array of regular expressions and URLs, and then call `Surveyor::evaluateUrl()`:

```
$Surveyor = new Surveyord([
    ['/(?:stories\/bedtime\/[\w_-]*)/', 'https://example.com/stories/bedtime/'],
    ['/(?:stories(?:|\/[\w_-]*))/', 'https://example.com/stories/'],
]);
echo $Surveyor->evaluateUrl('https://example.com/stories/bedtime/goodnight-moon');
// Yields `https://example.com/stories/bedtime/`
```

Possible URLs are evaluated in sequence, and returned as soon as a match is found. If no match is found, then the URL originally passe dto `evaluateUrl()` is returned. This means that you can easily use Surveyor inside a Climber call, and it will fall back to whatever Climber wants to do with that URL if no matches are found. Like so:

```
$Surveyor = new Surveyord([
    ['/(?:stories\/bedtime\/[\w_-]*)/', 'https://example.com/stories/bedtime/'],
    ['/(?:stories(?:|\/[\w_-]*))/', 'https://example.com/stories/'],
]);
$Climber = new Climber(
  new Tree(new Spotter\WordPress(wp_get_nav_menu_items($menuID))),
  $Surveyor->evaluateUrl(get_permalink(get_the_ID()))
);
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~107 days

Recently: every ~118 days

Total

6

Last Release

2493d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/45ef59bc24058cd989f522d8a6f8cc9b9aa31721b765d2b8552500dcc268e15d?d=identicon)[alwaysblank](/maintainers/alwaysblank)

---

Top Contributors

[![alwaysblank](https://avatars.githubusercontent.com/u/23412884?v=4)](https://github.com/alwaysblank "alwaysblank (77 commits)")

---

Tags

wordpress

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/livy-climber/health.svg)

```
[![Health](https://phpackages.com/badges/livy-climber/health.svg)](https://phpackages.com/packages/livy-climber)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
