Looper Provider: Menu - Featured Image

I’m really enjoying the Menu Looper Provider! I’ve used it so many different ways so far and I’m sure I’ll find many more ways to use it.

2 questions:

  1. is there any way to reference a featured image attached to the page/post that the menu item refers to? I’m trying to build out a dynamically generated Mega Menu, but can’t figure out how to reference an image.

  2. How can I reference a location rather than a menu name in the Provider? This exists when selecting the menu from a menu element, but isn’t available in the Menu Provider area. (I need a solution, but also possible to add as a Feature Request?)
    image

I was able to work out my First/Featured Image question using this:

{{ post.featured_image({"post": looper.field({"key":"object_id"})}) }}

also, I’m not sure if this is user error or a glitch, but:

{{ looper.field({“key”:“post_title”}) }} - only pulls titles for CPTs and and Custom Links

{{ looper.field({“key”:“title”}) }} - pulls everything

Hello @splaquet,

The post_title pertains to the title of the page, post, or custom post type. I would recommend running the debug first {{dc:looper:debug_consumer}}. This should return the data that you can use to display a title or specific field for that particular consumer.

We would be happy to double check your site if we can log in. You can create a secure note in your next reply with the following info:
– Link to your site
– WP login URL
– WP username
– WP password
– WP Administrator Role
– Confirmation that we can access and make changes to your site

To know how to create a secure note, please check this out: How The Forum Works

image

Best Regards.

I’ve got everything else figured out, but I need to reference a location rather than a menu name in the Provider. can that feature be added?

I’m using Inline Navigation in the footer and choosing Location instead of Menu. it’s working great when I apply the footer throughout the entire WPMU. the header… not so much. it’ll crash the site until I manually set a Menu Name in the provider.

Hello @splaquet,

I have added the Menu Location for the Looper Provider Menu as a feature request.

Thanks.

1 Like

I don’t suppose there’s a workaround (adding Location option to Looper Provider) I could use?

Hello @splaquet,

At the moment, there isn’t a built-in workaround to add a Location option to the Looper Provider for menus. It would require custom development to achieve this functionality. We have added your request as a feature request so our development team can consider adding this option in a future update.

Thanks for understanding

No worries, totally understood. I had to ask, just to make sure I wasn’t missing something.

Not sure if this will make things easier, but I had Codex kick me out some updated code.

# Cornerstone Looper Provider: Menu Location Support

## Request

Please add Menu Location support to the Cornerstone **Looper Provider → Menu** control.

The Inline Navigation element already allows a user to select either a specific menu or a registered Menu Location, such as `Primary Menu` or `Footer Menu`. The Looper Provider → Menu control currently exposes only menus returned by `wp_get_nav_menus()`.

## Expected behavior

The Menu control should expose:

```text
menu:<term_id>
location:<registered_location_slug>
```

When `location:<slug>` is selected, resolve the current assignment at render time:

```php
$locations = get_nav_menu_locations();
$menu_id = $locations[ $slug ] ?? 0;
```

This allows the Looper to follow the menu currently assigned to that location on each site.

## Current patch

### 1. Add locations to the Menu choices

File:

```text
includes/dynamiccontent/menu.php
```

After the existing `wp_get_nav_menus()` loop:

```php
foreach ( get_registered_nav_menus() as $location => $label ) {
    $out[] = [
        'value' => 'location:' . $location,
        'label' => sprintf( __( 'Menu Location: %s', 'cornerstone' ), $label ),
    ];
}
```

### 2. Resolve location values in the Menu Looper

File:

```text
includes/loopers/menu.php
```

Before `wp_get_nav_menu_items()`:

```php
if ( is_string( $menu_id ) && strpos( $menu_id, 'location:' ) === 0 ) {
    $location  = substr( $menu_id, 9 );
    $locations = get_nav_menu_locations();
    $menu_id   = isset( $locations[ $location ] ) ? (int) $locations[ $location ] : 0;
} elseif ( is_string( $menu_id ) && strpos( $menu_id, 'menu:' ) === 0 ) {
    $menu_id = (int) substr( $menu_id, 5 );
}
```

Keep the existing stale-menu guard:

```php
$items = wp_get_nav_menu_items( $menu_id );

if ( ! is_array( $items ) || empty( $items ) ) {
    return [];
}
```

## Compatibility requirements

- Existing numeric menu IDs must continue to work.
- Existing `menu:<term_id>` values should be accepted for exported or migrated data.
- Location resolution must use the active site’s `get_nav_menu_locations()` result.
- WPML and other `wp_get_nav_menu_items()` filters must continue to run.
- Current-menu classes should continue through `_wp_menu_item_classes_by_context()`.
- An unassigned or deleted location should return an empty result without warnings or fatals.
- Choice labels must remain translation-ready.

## Verification performed

- PHP lint passed for both modified files.
- Seven registered Menu Locations were exposed by the dynamic Menu choices.
- `location:primary` resolved to the assigned menu and returned 21 menu items.
- A direct menu ID continued to return 21 menu items.

## Upstream note

The production patch is currently in the Pro/Cornerstone theme files. Please implement this in the Cornerstone source and release it through the normal update process so the behavior is not lost during a theme/plugin update.

Thank you for sharing the code. We’ll check it out. :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.