ThemeShaper Forums » Thematic

[closed]

Can you make parent menu items non-clickable?

(20 posts)
  • Started 10 years ago by krhysling
  • Latest reply from elderberry
  • This topic is not resolved

Tags:

  1. krhysling
    Member

    I want menu items that have children to be non-clickable. Basically, they should just be containers for the child menu items.

    For an example of what I mean, see my current Joomla site (that I'm trying to convert to Wordpress and Thematic) at http://www.denverwaldorf.org . The "About DWS" top-level menu isn't clickable and it's two children that have children themselves ("Faculty Bios" and "Governance") are not clickable either.

    How can this be accomplished?

    If you need to see my current Thematic-based site, it's at http://www.denverwaldorf.dreamhosters.com but I have to warn you, it's a mess. :-)

    Thanks!

    Posted 10 years ago #
  2. Hey,

    don't think that this could be don by passing an argument to wp_page_menu(). Let me see if there's a plugin available.

    Cheers,

    Chris

    Posted 10 years ago #
  3. krhysling
    Member

    Chris,

    I'm not sure if this helps but I believe the following plugin has an option like what I'm looking for.

    http://weeatbricks.com/2008/01/07/new-wordpress-plugin-for-creating-a-drop-down-navigation-menu-using-jquery/

    They say "Parents pages can can be either links to pages or not if required."

    Thanks,
    Kieran

    Posted 10 years ago #
  4. Kieran,

    thanks a lot for this information, I will look into this plugin and check if we can adopt the technique for our menu.

    Cheers,

    Chris

    Posted 10 years ago #
  5. krhysling
    Member

    Hi, Chris.

    Have you had an opportunity to look into this yet? I just wanted to let you know I am still interested.

    Also, might it be possible to accomplish this by somehow filtering wp_page_menu like Ian mentions here: http://themeshaper.com/wordpress-menu-tricks/ ? Just throwing out some ideas...

    Thanks,
    Kieran

    Posted 10 years ago #
  6. Hey Kieran,

    sorry!!!!

    A couple of more or less sleepless nights .. and haven't thought 'bout Ian's article.

    Here is how it works explained for one replacement. I'm replacing the 'Thematic' link in my menu against a non-clickable text .. Submenus below 'Thematic' are still working:

    The code for the child theme's functions.php:

    function add_menuclass($ulclass) {
    return preg_replace('/(<a href="http:\/\/localhost\/wupperpiraten\/thematic-2\/" title="Thematic">Thematic<\/a>)/', '<span>Thematic</span>', $ulclass, 1);
    }
    add_filter('wp_page_menu','add_menuclass');
    
    And the code for your style.css:

    .sf-menu span {
    border-bottom:1px solid #CCCCCC;
    border-left:1px solid #CCCCCC;
    border-top:1px solid #CCCCCC;
    padding:9px 13px;
    display:block;
    position:relative;
    }
    `

    Tested and Approved.

    If you need to test the Regular Expression, I use reWork

    Cheers,

    Chris

    Posted 10 years ago #
  7. krhysling
    Member

    Chris,

    Sorry to hear about the sleepless nights. I've had a few of those myself lately. :-)

    This approach seems workable for me but can you explain a little more how I would do it for additional menu items? Would I just add a preg_replace call for each one I wanted to modify or would I need a separate filter function for each one?

    Thanks for all your help!

    Kieran

    Posted 10 years ago #
  8. Kieran,

    everything can be done in one function with one preg_replace call for each top menu item you want to replace.

    Open the blog in your browser and change to source view .. search for the line starting with <div class="menu"> .. now search for the first top menu item you want to replace .. it should look like <a href="http://your.blog.com/menu-item/" title="menu-item"> .. copy this part over to your functions.php .. it'll become return preg_replace('/(<a href="http:\/\/your.blog.com\/menu-item\/" title="menu-item">menu-item<\/a>)/', '<span>menu-item</span>', $ulclass, 1);.

    Hope this helps.

    Cheers,

    Chris

    Posted 10 years ago #
  9. krhysling
    Member

    Chris,

    I was thinking about this more and wondered if there is a way to do it without hardcoding the page urls. I'd like to avoid having to update those as users add pages.

    Is it possible to programmatically determine if a page has children? If so, could you do something like this (in pseudocode):

    if page has children, replace page's href=".*" with href="#"

    It seems like that could work but I don't know enough about Wordpress or PHP to be certain.

    Kieran

    Posted 10 years ago #
  10. krhysling
    Member

    Chris,

    Any thoughts on what I posted above about avoiding the hardcoding?

    Another thought I had was that if there is no direct way to determine if a page has children, maybe you can query what the parent is for each page and create a list of parents?

    If I am asking too much here, just tell me to go away. :-)

    Kieran

    Posted 10 years ago #
  11. Kieran,

    you're not asking to much and I won't tell you to go away .. it's just a question of time .. I can tell you that it is possible, but I can't do it right now. If it is something you want to have right now you should ask Danny for a quote.

    Cheers,

    Chris

    Posted 10 years ago #
  12. krhysling
    Member

    I'm not in a big hurry at the moment and I really appreciate the great support you provide for Thematic at no cost.

    Can you suggest when I should check in with you about this? I understand how busy you are and I don't want to nag. Maybe ping you in a couple of weeks?

    Thanks again,
    Kieran

    Posted 10 years ago #
  13. Jamie Mitchell
    Member

    yo fellow thematicians

    i have been searching for a similar solution, to disable the parent page so the user is forced to click the child page in the dropdown, replacing the link with just a #

    this is what i did with Chris's code above

    function add_menuclass($ulclass) {
    return preg_replace('/(<a href="http:\/\/yourwebsite.com\/parent">Parent<\/a>)/', '<a href="#">Parent</a>', $ulclass, 1);
    }
    add_filter('wp_page_menu','add_menuclass');

    beautiful :-)

    ...as for having it for all parent pages automaticly, i don't see how that would be possible, as you need the actual url to replace...

    beside what effort is it to just crack open and edit your functions.php when you add a page, a couple of minutes work that's all.

    J

    Posted 10 years ago #
  14. Jamie Mitchell
    Member

    oooh...

    Chris if your tuned in, how do i add a multiple links to change, rather than just the link one as above...?

    thanks in advance.

    Posted 10 years ago #
  15. krhysling
    Member

    Jamie,

    It's definitely possible to do it automatically; I just don't have the php skills. I may have to learn though!

    My motivation for wanting to do it automatically is that, otherwise, every time my clients add a page, they have to contact me to fix the menu. That's a hassle for both of us.

    Posted 10 years ago #
  16. Jamie Mitchell
    Member

    Howdy...

    ok, found a solution for all those waiting in suspense :-)

    it ain't a handcoded php solution but it works.

    using the page list plus plugin

    i can un-tick any page so it becomes unlinked.

    without going into any details as everybody will style there menu differently, you will need to tweak your css for the sf-menu, so styling is applied to a sf-menu-li, rather than sf-menu a

    some tips:

    use line-height of the same value as you #access rather than padding in the sf-menu li, except for left/right padding is needed.

    and user cursor:pointer as well...

    Posted 10 years ago #
  17. krhysling
    Member

    Thanks for pointing out this plugin. I hadn't seen that one before.

    I will definitely give it a try.

    Posted 10 years ago #
  18. it's much easier.. you don't have to hard code anything and it works great.. so.. set the parent item as an external link and at the value of the link put #. and that's all falks :p. just as simple as that

    Posted 8 years ago #
  19. i forgot to mention. it's the method for joomla.

    Posted 8 years ago #
  20. elderberry
    Member

    Page-Links-To is a plugin that will let you set the url of any page to #.

    Posted 8 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.