Skip Navigation

[Resolved] Conditional display of menu based on post relationship

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 7 replies, has 2 voices.

Last updated by Shane 6 years ago.

Assisted by: Shane.

Author
Posts
#1188130

Tell us what you are trying to do?
I need to display a menu based on the post relationship. The website is divided into regions. Each region should have a region specific menu that also has customs link 'news'. These custom links should dan show a news archive prefiltered with the current region.

So is there a conditional tag based on post relationship. And can i write custom links based on the current region.

Is there any documentation that you are following?
No

Is there a similar example that we can see?
No

What is the link to your site?
hidden link

#1188227

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Glenn,

Thank you for getting in touch.

These custom links will be on the site's main menu ? If so then it wouldn't be possible to have conditional menu items based on a relationship value.

Unless this is something that is hardcoded into your theme's header file.

Thanks,
Shane

#1188234

Hi Shane,

no the region menu will be a separate menu that is placed in the sidebar. So either i make a widgetarea to load the menu in or i will create a separate menu area in the layout.

But i don't want my client to have to create a custom menu for every region with the customlinks. It would be so much better if i can automatically do this.

For example:
Each region has the following post types: news, vendors, blogs, events. All the post type are children of 'Regio' (post relationship).

What i would like is to have a menu(or sidebar) that checks which region the (custom) post is related to and show a menu/sidebar based on this. So something like a conditinal:

if post relation is 'region x' show menu 'region x'.

This would already help a lot. What would be even better is if the custom urls in the menu also get build based on the region.
So if i am on region 'westland' and i click on news than it shows an archive with url parameter 'westland' and this only shows 'Westland' news.

I hope i explained my problem accurately. Otherwise let me know.

Mvg,

Glenn Windhouwer

#1188242

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Glenn,

I understand now.

It is possible if the menu is going to be an html coded menu.

This is because you're not able to have a conditional cell. If conditional cells were possible then you would be able to do this much easier.

However you will need to hardcode the html in a visual editor cell for the menus and wrap each menu in a conditional statement.

Please let me know if this helps.

Thanks,
Shane

#1188967

Hi Shane,

ok i think i can figure out your solution. I just need to know what the conditional code would be for the postrelationship. Could you give me an example?

Kind regards

#1189102

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Glen,

So the conditionals are easiest done from the child side so an example would be.

[wpv-conditional if="( '[wpv-post-title item="@manufacturer-car.parent"]' eq '' )"]

This is a test

[/wpv-conditional]

I'm getting the post title of the parent of the car cpt. So "car" is the slug of the child and "manufacturer" is the slug of the parent cpt.

Please let me know if this helps.

Thanks,
Shane

#1189128

Hi Shane,

thank you for your reply. I will look into this on friday and will let you know if it solves my problems.

Kind regards,

Glenn

#1189165

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Glenn,

Awesome looking forward to hearing the results.

Thanks,
Shane