Jump to content
mojocreator

Category-sensitive menu

Recommended Posts

mojocreator    0
mojocreator

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 in_category function 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...


remove_action( 'brandnav_after_nav', 'brandnav' );

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 http://staging.ortho360.com/ 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

Share this post


Link to post
Share on other sites
Rob    547
Rob

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 http://www.pagelines.com/pros or to http://www.odesk.com 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.


Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
mojocreator    0
mojocreator

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:


<?php if ( is_user_logged_in() ) {

		 wp_nav_menu( array( 'theme_location' => 'logged-in-menu' ) ); /* if the visitor is logged in, this primary navigation will be displayed */

} else {

		 wp_nav_menu( array( 'theme_location' => 'visitor-menu' ) ); /* if the visitor is NOT logged in, this primary navigation will be displayed. if a single menu should be displayed for both conditions, set the same menues to be displayed under both conditions through the Wordpress backend */

} ?>

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

<?php remove_action( $tag, $function_to_remove, $priority, $accepted_args ); ?>

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

http://wordpress.org...tags?replies=13

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

Share this post


Link to post
Share on other sites
mojocreator    0
mojocreator

Here's the back half.

In ~pagelinessectionbrandnavsection.php the code is called here:


<div class="brandnav-nav main_nav fix">

<?php

wp_nav_menu( array('menu_class' => 'main-nav tabbed-list'.pagelines_nav_classes(), 'container' => null, 'container_class' => '', 'depth' => 3, 'theme_location'=>'brandnav', 'fallback_cb'=>'pagelines_nav_fallback') );


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

?>

</div>

<div class="clear"></div>

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

Share this post


Link to post
Share on other sites
mojocreator    0
mojocreator

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.

Share this post


Link to post
Share on other sites
Danny    1,327
Danny

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.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
Simon    247
Simon

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.

Share this post


Link to post
Share on other sites
mojocreator    0
mojocreator

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.

Share this post


Link to post
Share on other sites
Simon    247
Simon

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Similar Content

    • bnapoli
      By bnapoli+
      http://731.34b.myftpupload.com/ this website is using the NavPro navigation in Platform 5. It has a lot of menu items, so it breaks to two lines when the window is sized down. What is the media query to make the navigation either a) switch to "mobile mode" at a higher width, or b ) expand the nav into two lines. Thanks
    • nadielp
      By nadielp+
      Hi Everyone,
      I am trying to get a single navigation item to center. I am using a scroll menu in the navigation component of Impulse. I would like to have the item in the center of the page but it defaults right. I tried setting the item to center a few different ways and nothing is working. I added {
        display: inline-block;
        position: relative;
        text-align: center;
      }
      but that didn't work...any help would be appreciated. Site is at http://vetpaw.org/new
       
      Thanks!
      Daniel
    • yemoonyah
      By yemoonyah+
      I just installed and added the Flipper section to my home page and it makes my navigation/menu bar items disappear.
      They do show up again when scrolling down and everything seems normal on the other pages.
      http://yemoonyah.com
      Thanks.
       
    • Houston Haynes
      By Houston Haynes+
      I'm still "piercing the veil" of platform 5, with page navigation the current subject of interest. I worked with a few plugins (the most useful being Next Page Not Next Post) but I wanted to take a step back and start with an example - and see if I could get a bit of help "inside the beltway". 
      What I'm looking to do is substantially similar to the pagelines docs pages - see my annotated screenshots attached. At the top of a "child" page I want a link back to the "parent" page - and at the bottom of that "child" page I want to place a similar link to the "grandchild" page. At the bottom of each grandchild page I want there to be navigation "buttons" to sibling pages in the hierarchy. 
      "Next Page Not Next Post" handles what I'm expecting for "sibling" navigation, but I'm having a bit of trouble getting over the logistical hump of applying that functionality to my page "Template C" instance only. And per the attached examples, while researching how to solve this problem I see on the Pagelines site *itself* that the navigation elements are in place - and I especially like the oval button formatting of the sibling page navigation.
      So - really, my question is two-part:
      Are there plugins/code snippets/tutorials/threads here that show how Pagelines achieved their page hierarchy nagivation, and  Is there a tutorial (or advice from generous contributors here) on how to use the PHP templates to override the content portion of the page to add the navigation elements? Thanks in advance!


    • hungryitalian
      By hungryitalian
      What is the equivalent to DMS2's PostNav section in PL5?  I'm looking for PREVIOUS/NEXT buttons that show the associated post names for the previous and next posts.
      Thanks,
      J.D.
×