All Projects → Log1x → Navi

Log1x / Navi

Licence: mit
A developer-friendly alternative to the WordPress NavWalker.

Labels

Projects that are alternatives of or similar to Navi

Customizr
Customizr WordPress Theme
Stars: ✭ 133 (-5%)
Mutual labels:  wordpress
Wordpress Scanner
Wordpress Vulnerability Scanner
Stars: ✭ 137 (-2.14%)
Mutual labels:  wordpress
Setup Ghost Blog
Script to install your own Ghost blog, with Nginx and ModSecurity/Naxsi web application firewall. Supports multiple blogs.
Stars: ✭ 140 (+0%)
Mutual labels:  wordpress
Gravity Forms Iframe
A Gravity Forms add-on to embed a form in an auto-resizing iframe on external sites.
Stars: ✭ 134 (-4.29%)
Mutual labels:  wordpress
React With Wordpress
🔥 Example of react application to access WordPress REST API
Stars: ✭ 137 (-2.14%)
Mutual labels:  wordpress
Image Optimize Command
Easily optimize images using WP CLI
Stars: ✭ 138 (-1.43%)
Mutual labels:  wordpress
Wp Spider Cache
Your friendly neighborhood caching solution for WordPress
Stars: ✭ 133 (-5%)
Mutual labels:  wordpress
Gdpr
This plugin is meant to assist a Controller, Data Processor, and Data Protection Officer (DPO) with efforts to meet the obligations and rights enacted under the GDPR.
Stars: ✭ 141 (+0.71%)
Mutual labels:  wordpress
Fragment Cache
WordPress plugin for partial and async caching.
Stars: ✭ 135 (-3.57%)
Mutual labels:  wordpress
Google Docs Add On
Publish to WordPress from Google Docs
Stars: ✭ 140 (+0%)
Mutual labels:  wordpress
Base Camp
Awesome WordPress starter theme for developers based on modern web technologies.
Stars: ✭ 135 (-3.57%)
Mutual labels:  wordpress
Wp Tailwind
A WordPress starter theme that utilizes Tailwind + PurgeCSS.
Stars: ✭ 135 (-3.57%)
Mutual labels:  wordpress
Core
All of the required core code
Stars: ✭ 139 (-0.71%)
Mutual labels:  wordpress
Hrcloud2
A full-featured home hosted Cloud Drive, Personal Assistant, App Launcher, File Converter, Streamer, Share Tool & More!
Stars: ✭ 134 (-4.29%)
Mutual labels:  wordpress
Wp Api Menus
🔡 Menu routes for WordPress JSON REST API.
Stars: ✭ 140 (+0%)
Mutual labels:  wordpress
Fly Dynamic Image Resizer
Fly Dynamic Image Resizer plugin for WordPress
Stars: ✭ 133 (-5%)
Mutual labels:  wordpress
Wprecon
WPrecon (WordPress Recon), is a vulnerability recognition tool in CMS Wordpress, developed in Go and with scripts in Lua.
Stars: ✭ 135 (-3.57%)
Mutual labels:  wordpress
Activello
WordPress Bootstrap blog theme with doeznes of options using WordPress Customizer
Stars: ✭ 141 (+0.71%)
Mutual labels:  wordpress
Wp Toolbelt
A lightweight, multi-purpose, WordPress plugin with a focus on privacy and speed
Stars: ✭ 141 (+0.71%)
Mutual labels:  wordpress
Health Check
Health Check is a WordPress plugin that will perform a number of checks on your WordPress install to detect common configuration errors and known issues.
Stars: ✭ 139 (-0.71%)
Mutual labels:  wordpress

Navi

Latest Stable Version Total Downloads Build Status

Hate the WordPress NavWalker? Me too.

Navi is a developer-friendly alternative to the NavWalker. Easily build your WordPress menus using an iterable object inside of a template/view.

Requirements

Installation

Bedrock (or Sage)

Install via Composer:

$ composer require log1x/navi

Manual

Download the latest release .zip and install into wp-content/plugins.

Usage

Check out the examples folder to see how to use Navi in your project.

Basic Usage

<?php

use Log1x\Navi\Navi;

$navigation = (new Navi())->build('primary_navigation');

if ($navigation->isEmpty()) {
  return;
}

return $navigation->toArray();

When building the navigation menu, Navi retains the menu object and makes it available using the get() method.

By default, get() returns the rawwp_get_nav_menu_object() allowing you to access it directly.

Optionally, you may pass a key and default to call a specific object key with a fallback have it be null, empty, or not set.

$navigation->get()->name;
$navigation->get('name', 'My menu title');

Accessing Page Objects

If 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.

# Blade
{{ get_post_type($item->objectId) }}

# PHP
<?php echo get_post_type($item->objectId); ?>

Accessing Custom Fields

In 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.

Below we'll get a label override field attached to our menu using ACF – falling back to the default menu label if the field is empty.

# Blade
{{ get_field('custom_nav_label', $item->id) ?: $item->label }}

# PHP
<?php echo get_field('custom_nav_label', $item->id) ?: $item->label; ?>

Example Output

When calling build(), Navi will parse the passed navigation menu and return a fluent container containing your menu items. To return an array of objects, simply call ->toArray().

By default, build() calls primary_navigation which is the default menu theme location on Sage.

array [
  5 => {
    +"active": true
    +"activeAncestor": false
    +"activeParent": false
    +"children": false
    +"classes": "example"
    +"dbId": 5
    +"description": false
    +"id": 5
    +"label": "Home"
    +"objectId": "99"
    +"parent": false
    +"slug": "home"
    +"target": "_blank"
    +"title": false
    +"url": "https://sage.test/"
    +"xfn": false
  }
  6 => {
    +"active": false
    +"activeAncestor": false
    +"activeParent": false
    +"children": array [
      7 => {
        +"active": false
        +"activeAncestor": false
        +"activeParent": false
        +"children": array [
          ...
        ]
        +"classes": false
        +"dbId": 7
        +"description": false
        +"id": 7
        +"label": "Example"
        +"objectId": "101"
        +"parent": 6
        +"slug": "example"
        +"target": false
        +"title": false
        +"url": "#"
        +"xfn": false
      }
    ]
    +"classes": false
    +"dbId": 6
    +"description": false
    +"id": 6
    +"label": "Sample Page"
    +"objectId": "100"
    +"parent": false
    +"slug": "sample-page"
    +"target": false
    +"title": false
    +"url": "https://sage.test/sample-page/"
    +"xfn": false
  }
]

That being said, depending on how deep your menu is– you can ultimately just keep looping over ->children indefinitely.

Bug Reports

If you discover a bug in Navi, please open an issue.

Contributing

Contributing whether it be through PRs, reporting an issue, or suggesting an idea is encouraged and appreciated.

License

Navi is provided under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].