{"id":15628402,"url":"https://github.com/log1x/navi","last_synced_at":"2025-04-13T08:56:49.534Z","repository":{"id":43189541,"uuid":"192903967","full_name":"Log1x/navi","owner":"Log1x","description":"A developer-friendly alternative to the WordPress NavWalker.","archived":false,"fork":false,"pushed_at":"2024-10-21T23:10:58.000Z","size":90,"stargazers_count":337,"open_issues_count":1,"forks_count":30,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-06T05:11:12.224Z","etag":null,"topics":["navigation-menu","navwalker","sage","wordpress"],"latest_commit_sha":null,"homepage":"https://github.com/Log1x/navi","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Log1x.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"Log1x"}},"created_at":"2019-06-20T10:59:34.000Z","updated_at":"2025-04-04T09:40:28.000Z","dependencies_parsed_at":"2023-11-17T00:10:55.854Z","dependency_job_id":"6e9c5f4d-06cb-481c-8cf0-48e7589b8f47","html_url":"https://github.com/Log1x/navi","commit_stats":{"total_commits":81,"total_committers":12,"mean_commits":6.75,"dds":0.2098765432098766,"last_synced_commit":"97fa923a1eb1aa92d17984117b8e0f56a0a818ab"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Log1x%2Fnavi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Log1x%2Fnavi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Log1x%2Fnavi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Log1x%2Fnavi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Log1x","download_url":"https://codeload.github.com/Log1x/navi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248688544,"owners_count":21145764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["navigation-menu","navwalker","sage","wordpress"],"created_at":"2024-10-03T10:22:27.312Z","updated_at":"2025-04-13T08:56:49.515Z","avatar_url":"https://github.com/Log1x.png","language":"PHP","funding_links":["https://github.com/sponsors/Log1x"],"categories":[],"sub_categories":[],"readme":"# Navi\n\n![Latest Stable Version](https://img.shields.io/packagist/v/log1x/navi.svg?style=flat-square)\n![Total Downloads](https://img.shields.io/packagist/dt/log1x/navi.svg?style=flat-square)\n![Build Status](https://img.shields.io/github/actions/workflow/status/log1x/navi/main.yml?branch=master\u0026style=flat-square)\n\nHate the WordPress NavWalker? **Me too**.\n\nNavi is a developer-friendly alternative to the NavWalker. Easily build your WordPress menus using an iterable object inside of a template/view.\n\n## Requirements\n\n- [PHP](https://secure.php.net/manual/en/install.php) \u003e= 8.0\n\n## Installation\n\n### Bedrock (or Sage)\n\nInstall via Composer:\n\n```bash\n$ composer require log1x/navi\n```\n\n### Manual\n\nDownload the [latest release](https://github.com/Log1x/navi/releases/latest) `.zip` and install into `wp-content/plugins`.\n\n## Usage\n\nBuilding your menu can be done by passing your menu location to `Navi::make()-\u003ebuild()`:\n\n```php\nuse Log1x\\Navi\\Navi;\n\n$menu = Navi::make()-\u003ebuild('primary_navigation');\n```\n\nBy default, `build()` uses `primary_navigation` if no menu location is specified.\n\nRetrieving an array of menu items can be done using `all()`:\n\n```php\nif ($menu-\u003eisNotEmpty()) {\n    return $menu-\u003eall();\n}\n```\n\n\u003e [!NOTE]\n\u003e Check out the [**examples**](examples) folder to see how to use Navi in your project.\n\n### Menu Item Classes\n\nBy default, Navi removes the default WordPress classes from menu items such as `menu-item` and `current-menu-item` giving you full control over your menu markup while still passing through custom classes.\n\nIf you would like these classes to be included on your menu items, you may call `withDefaultClasses()` before building your menu:\n\n```php\n$menu = Navi::make()-\u003ewithDefaultClasses()-\u003ebuild();\n```\n\nIn some situations, plugins may add their own classes to menu items. If you would like to prevent these classes from being added, you may pass an array of partial strings to `withoutClasses()` match against when building.\n\n```php\n$menu = Navi::make()-\u003ewithoutClasses(['shop-'])-\u003ebuild();\n```\n\n### Accessing Menu Object\n\nWhen building the navigation menu, Navi retains the menu object and makes it available using the `get()` method.\n\nBy default, `get()` returns the raw [`wp_get_nav_menu_object()`](https://codex.wordpress.org/Function_Reference/wp_get_nav_menu_object) allowing you to access it directly.\n\n```php\n$menu-\u003eget()-\u003ename;\n```\n\nOptionally, you may pass a `key` and `default` to call a specific object key with a fallback when the value is blank:\n\n```php\n$menu-\u003eget('name', 'My menu title');\n```\n\n### Accessing Page Objects\n\nIf your menu item is linked to a page object (e.g. not a custom link) – you can retrieve the ID of the page using the `objectId` attribute.\n\nBelow is an example of getting the post type of the current menu item:\n\n```php\n$type = get_post_type($item-\u003eobjectId)\n```\n\n### Accessing Custom Fields\n\nIn a scenario where you need to access a custom field attached directly to your menu item – you can retrieve the ID of the menu item using the `id` attribute.\n\nBelow we'll get a label override field attached to our menu [using ACF](https://www.advancedcustomfields.com/resources/adding-fields-menus/) – falling back to the default menu label if the field is empty.\n\n```php\n$label = get_field('custom_menu_label', $item-\u003eid) ?: $item-\u003elabel;\n```\n\n### Acorn Usage\n\nIf you are using Navi alongside [Acorn](https://roots.io/acorn/) (e.g. Sage), you may generate a usable view component using Acorn's CLI:\n\n```sh\n$ wp acorn navi:make Menu\n```\n\nOnce generated, you may use the [view component](https://laravel.com/docs/11.x/blade#components) in an existing view like so:\n\n```php\n\u003cx-menu name=\"footer_navigation\" /\u003e\n```\n\nTo list all registered locations and their assigned menus, you can use the list command:\n\n```sh\n$ wp acorn navi:list\n```\n\n## Example Output\n\nWhen calling `build()`, Navi will retrieve the WordPress navigation menu assigned to the passed location and build out an array containing the menu items.\n\nAn example of the menu output can be seen below:\n\n```php\narray [\n  5 =\u003e {\n    +\"active\": true\n    +\"activeAncestor\": false\n    +\"activeParent\": false\n    +\"classes\": \"example\"\n    +\"dbId\": 5\n    +\"description\": false\n    +\"id\": 5\n    +\"label\": \"Home\"\n    +\"object\": \"page\"\n    +\"objectId\": \"99\"\n    +\"parent\": false\n    +\"slug\": \"home\"\n    +\"target\": \"_blank\"\n    +\"title\": false\n    +\"type\": \"post_type\"\n    +\"url\": \"https://sage.test/\"\n    +\"xfn\": false\n    +\"order\": 1\n    +\"parentObjectId\": false\n    +\"children\": false\n  }\n  6 =\u003e {\n    +\"active\": false\n    +\"activeAncestor\": false\n    +\"activeParent\": false\n    +\"classes\": false\n    +\"dbId\": 6\n    +\"description\": false\n    +\"id\": 6\n    +\"label\": \"Sample Page\"\n    +\"object\": \"page\"\n    +\"objectId\": \"100\"\n    +\"parent\": false\n    +\"slug\": \"sample-page\"\n    +\"target\": false\n    +\"title\": false\n    +\"type\": \"post_type\"\n    +\"url\": \"https://sage.test/sample-page/\"\n    +\"xfn\": false\n    +\"order\": 2\n    +\"parentObjectId\": false\n    +\"children\": array [\n      7 =\u003e {\n        +\"active\": false\n        +\"activeAncestor\": false\n        +\"activeParent\": false\n        +\"classes\": false\n        +\"dbId\": 7\n        +\"description\": false\n        +\"id\": 7\n        +\"label\": \"Example\"\n        +\"object\": \"custom\"\n        +\"objectId\": \"101\"\n        +\"parent\": 6\n        +\"slug\": \"example\"\n        +\"target\": false\n        +\"title\": false\n        +\"type\": \"custom\"\n        +\"url\": \"#\"\n        +\"xfn\": false\n        +\"order\": 3\n        +\"parentObjectId\": 100\n        +\"children\": array [\n          ...\n        ]\n      }\n    ]\n  }\n]\n```\n\n## Bug Reports\n\nIf you discover a bug in Navi, please [open an issue](https://github.com/Log1x/navi/issues).\n\n## Contributing\n\nContributing whether it be through PRs, reporting an issue, or suggesting an idea is encouraged and appreciated.\n\n## License\n\nNavi is provided under the [MIT License](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flog1x%2Fnavi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flog1x%2Fnavi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flog1x%2Fnavi/lists"}