Jump to content


Photo
- - - - -

Category-sensitive menu

Navigation

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1 mojocreator

mojocreator

    Newbie

  • Members
  • 5 posts

Posted 11 September 2012 - 08:24 PM

Hello Pagelines,

I've got a client who needs a context-sensitive menu. If the client is in Austin, one menu needs to appear (default action). If they are in Bastrop, a different menu needs to be used.

In a standard Wordpress theme, I could use the

Please Login or Register to see this Hidden Content

and display the appropriate registered menu. I All it would require would be adding a category (or ideally a custom taxonomy of city names but let's keep the example on the easy side) to each page in the Bastrop section.

I have no idea how to do this in Pagelines.

My instinct is to do something like...

Please Login or Register to see this Hidden Content


Then re-register the hook using a custom function. I'm not totally clear on how that needs to work in this case. The site in question is at

Please Login or Register to see this Hidden Content

with "Bastrop" needing the alternate menu. I inherited some strange CSS menus from an Indian team on this dev account so ignore that behavior.

My primary concern is the contextual menu.

How would you de-register a menu in Pagelines and re-register a new context-sensitive snip of code?


Thanks!

Staff @ MojoCreator

#2 Rob

Rob

    One Smart Egg

  • Members
  • 13575 posts

Posted 11 September 2012 - 08:47 PM

PageLines doesn't operate the menu, it simply applies a style to it. The menus are created in Dashboard > Appearance > Menus. Your request is an extremely complicated one, involving WordPress core code. There may be some location specific plugins out there I'm not aware of, but this is a very tough request. You're not asking for the usual criteria of country or language, but down to the city. The web doesn't code IPs by city, so that's going to be really tough.

I would suggest you go to

Please Login or Register to see this Hidden Content

or to

Please Login or Register to see this Hidden Content

to find a suitable, skilled developer who might... just might, be able to help with this.

What I don't understand is... and please forgive me... why not just have a child menu under Austin for that group and another one for Bastrop? You'd create those in Dashboard > Appearance > Menus and simply make sure that the drop down menus are enabled.

#3 mojocreator

mojocreator

    Newbie

  • Members
  • 5 posts

Posted 11 September 2012 - 10:31 PM

My apologies, I'm learning Pagelines as I go here. I'm a theme developer out of SF (I'm on the Mojo Creator account here - based out of Austin)and I usually work with Hybrid Core. You have some really cool code in Pagelines, which I've had a chance to appreciate in some detail today.

I realize that Pagelines menus are managed by Wordpress. What I need shouldn't touch the core at all though. I could use a GeoIP but that would be overkill for a two-city solution.

There are several ways to to this. By using in_category I was over simplifying. The most natural thing to do would be to create a custom taxonomy then test to see if "Bastrop" was an assigned city for the page/post. If that post contained a "Bastrop" taxonomy entry, I could then serve the appropriate menu.

So here's what I have in mind.

Let's work by an easy example to understand. Here is how we would serve a menu for a logged in user vs a visitor.

We would register two menus called "logged-in-menu" and "visitor-menu". Then, inside of the navigation div (or NAV tag) we would call this function:

Please Login or Register to see this Hidden Content


The correct menu would be displayed based on whether or not our user was logged in.

In the case of Austin vs Bastrop, we would use a custom taxonomy and test for cities other than Austin (Bastrop being the only one for now). If the test for Bastrop evaluates to "false" then we would show the default menu. If it evaluates to "true" then we would show the Bastrop menu. It's not a terribly complex operation, when you put it in those terms.

The problem is that I can create menus for Bastrop and Austin but the way Pagelines is set up, I can only show one of them in a given menu area.

Thus, I can either re-write the core theme file (never a good idea) to include the test, or I could unhook the menu registration code and re-hook my own through functions.php in the Child.

Again, normally this is done with a remove_action followed by a do_action.

This assumes that I can remove a function

Please Login or Register to see this Hidden Content


Then create a new one that includes the test for a taxonomy (or category or logged in etc).

The result is a page-context sensitive menu.

The obvious remove/do combination isn't working and I would rather not edit the core theme code for Pagelines, as it could be wiped out by a later update.

Can you tell me how to unhook the menu registration and re-hook a custom one?


PS If you find yourself curious, this is how you test for a custom taxonomy

Please Login or Register to see this Hidden Content



None of it requires editing the core, or even the parent theme based on the way your hook/actions work.

#4 mojocreator

mojocreator

    Newbie

  • Members
  • 5 posts

Posted 11 September 2012 - 11:05 PM

Here's the back half.

In ~\pagelines\section\brandnav\section.php the code is called here:

Please Login or Register to see this Hidden Content


Copying that file to the child theme has no effect. Clearly you aren't a standard setup where I can override the PHP in that file - or I would have done so. Pagelines ignores changes in the child.

Right there you see the hook:

pagelines_register_hook( 'brandnav_after_nav', 'brandnav' ); // Hook

That's a dynamic function. It uses do_action on the back end.

How in the heck do I modify this? It's not a standard remove_action

#5 mojocreator

mojocreator

    Newbie

  • Members
  • 5 posts

Posted 12 September 2012 - 04:10 AM

From my digging this evening, it appears the Pagelines developers have not provided a simple way to de-register a hook. This is Wordpress, it has to be possible, but without a bit of guidance it could take me more time to figure out than the client wants to pay for.

Unfortunately, Pagelines also ignores changes to core files via child theme. Basically, the menu is stuck on stupid.

Want a different logged in menu? Yeah man, that sounds cool
Want a different menu for a page category or taxonomy? Man why are you so new school?

I'm irritable. I'll ask one more time for a solution but I've seen people spin circles for days trying to ask the same question around here.

#6 Danny

Danny

    Is Awesome!

  • Moderators
  • 16982 posts

Posted 12 September 2012 - 08:11 AM

Hi Mojo,

I will bring your topic to one of our developers attention and see what he recommends. I will reply here as soon as I have more information for you.

#7 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts

Posted 13 September 2012 - 12:31 AM

From my digging this evening, it appears the Pagelines developers have not provided a simple way to de-register a hook.

We have not change any core WordPress hooks. you can still easily de-register any style/script/action/filter.

This is Wordpress, it has to be possible, but without a bit of guidance it could take me more time to figure out than the client wants to pay for.
Unfortunately, Pagelines also ignores changes to core files via child theme. Basically, the menu is stuck on stupid.

If you mean overriding a section like the navbar, it takes about 10s to copy the section folder into a child theme, rename it and the edit it as much as you like.
Child sections always override core sections. You can use php to check if a user is logged in and show a different navbar then.

#8 mojocreator

mojocreator

    Newbie

  • Members
  • 5 posts

Posted 14 September 2012 - 03:55 PM

That's the thing - the child theme seemed to be ignoring changes to the file in /sections/ - not sure why.

Changing core functionality without hook/unhook isn't a good idea even in a child theme though. There is a reason why outfits like Genesis and Hybrid Core work this way.

#9 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts

Posted 14 September 2012 - 04:05 PM

Well, if you can figure out how to get the sections overriding in the child theme, you can always override the menu with the wordpress filters.