• Resolved irislely

    (@irislely)


    Hi there,
    I’m an absolute beginner playing around in a local child theme trying to understand stuff before actually putting it out there.
    I’m building a restaurant site for some friends and they’ve asked me to have the entries in the menubar change into the Italian equivalent on mouseover.
    I know this can be done using images but I would prefer to keep the site dynamic allowing my friends to change both menu entry and its mouseover entry through WP Admin.

    So, basically: if “#access li:hover” show contents of Title Attribute (using classes, I think?)

    Is that possible and if it is what do I need to change where?
    Thanks so much!
    Cheers, Iris

Viewing 15 replies - 1 through 15 (of 15 total)
  • If you know how to do this with images, you are really pretty close to being able to do this without them. The basic rollover idea is the same.

    I don’t think you want to use the title attribute— that is, <li><a title="title attribute" .... </a></li>— because browsers will already create a kind of popup out of that and you’d have some odd redundancy.

    But let’s start from the beginning. What code is generating the menu? Are you writing it? Is it a script you found? Are you using the WordPress menu API (highly recommended– love it)?

    Thread Starter irislely

    (@irislely)

    Hello s_ha_dum, thank you for your answer!
    I’m basing everything on the standard twenty-eleven menu (using a child theme of course!)
    I’ve only been adding pages through admin trying keep close to the base.

    In my header.php I have

    <li id="menu-item-65" class="translate menu-item menu-item-type-post_type menu-item-object-page menu-item-65">
    <a title="Nel bicchiere" href="https://localhost/here/?page_id=63">In het glas</a>
    <ul class="sub-menu">
    </li>

    So in my CSS I want to call menu-item-65 and onMouseOver I want the text to change from “In het glas” to ‘Nel bicchiere’.

    Instead of my trying to tell you about all the things I managed to do, could you tell me what I should do? My head is exploding. Sorry about being such a beginner!
    Thanks again!! Cheers

    TwentyEleven doesn’t have anything like that in header.php, though it does look a lot like what you’d see with view-source. Did you hard-code that into the child theme’s header.php? TwentyEleven’s menus are generated using the Menu API with values from wp-admin->Appearance->Menus and that would be the best way to keep these values editable from the backend.

    Thread Starter irislely

    (@irislely)

    You’re right, it was something I copied through firebug. No hard-coding in the header.php. I would in fact prefer doing everything through WPs dashboard but I guess changing individual menu items means selecting them separately in style.css, correct? No way around it?
    So playing around a bit I got my colors changing on mouseover for one of the menu-items and it’s child:

    #access li.menu-item-65 a {color: #000;}
    #access li.menu-item-65.current_page_item a {color: #fff;}
    #access li.menu-item-65 a:hover {
    	color:#ff8300;
    	background-color: #CCC;
    	border-bottom-color:#fff;
    }
    #access li.menu-item-77 a {color: #F0F;}
    #access li.menu-item-77.current_page_item a {color: #000;}
    #access li.menu-item-77 a:hover {
    	color: #93C;
    	background-color: #CCC;
    	border-bottom-color:#fff;
    }

    I added different background images to each individual item to see if that worked (yes) but I would prefer it just replacing the items text with it’s Italian version.
    I guess I’ll be needing JavaScript to do that right? No way to say something like #access li.menu-item-65 a:hover {text: "Nel bicchiere";} Sorry for the pseudo code.

    You’re right, it was something I copied through firebug. No hard-coding in the header.php.

    Ok. You said that code was in header.php. Don’t confuse the .php components with the HTML output. They are not the same.

    I would prefer it just replacing the items text with it’s Italian version. I guess I’ll be needing JavaScript to do that right?

    No. You don’t actually need Javascript, if you set this up right, but it may or may not be the easiest way, depending on how good you are with Javascript.

    Your options are:

    1. Use Javascript to extract that ‘title’ attribute and replace the anchor text when you mouse over, and of course undo that action.
    2. Use the walker_nav_menu_start_el filter (I think. I’d have to play with it to be sure.) to echo, say, a div with your translated content. Then you hide it with display:none, for example. You can pull it into place with :hover and you don’t need Javascript.
    Thread Starter irislely

    (@irislely)

    Wow thanks.. that opened up a new world! I decided to use Dennis Winters’ advice (https://www.ads-software.com/support/topic/how-to-show-the-description-of-the-menu?replies=9) and managed to create the “grid-10 omega” menu_class which seems to be working.

    The header.php is now pulling the walker instead of the existing wp_nav_menu( array( 'theme_location' => 'primary' ) );

    So then we get to the css.
    – I removed the
    from the customized functions.php so that the translation wouldn’t show under the menu item. It’s now attached to it.
    – I gave the description a color on hover (

    #menu-item-65:hover span{
    color:#0CF;
    }

    to make sure that I could see it.

    But now I’m a bit stuck again because of my lack of css knowledge:
    1. I know how to display:none; it to stop showing but how do I tell it to show the .sub (span class) and replace the existing text when I hover over it?
    2. Is there something like a menu-item-“wildcard” to stop it from being exclusively linked to a specific menu-item?

    I promise to learn more about css but can you give me a hint on how to continue?
    tx so much for your help again!

    Thread Starter irislely

    (@irislely)

    Sorry, forgot the backticks here:
    – I removed the </br> from the customized functions.php so that the translation wouldn’t show under the menu item. It’s now attached to it.

    Thread Starter irislely

    (@irislely)

    A good nights sleep and I got to this:

    #access ul li a span.sub { display: none; }
    #access ul li a:hover #access #menu-item { display: none; }
    #access ul li a:hover span.sub { display: inline; }
    #access a span{ padding-right:10px; color: #900; font-weight:bold;height:29px;font-size:inherit;}

    But how do I hide the original menu-item itself once its hovered over? Do I need to create a span or can I just use CSS? I’ve played around with line two but I’m getting more and more confused.

    #access ul li a:hover #access #menu-item { display: none; }

    So this line doesn’t work? If it does you are using ids improperly. An id should appear once and only once on a page. This line suggests that “#access” appears at least twice.

    I’d have to see the page markup– the html the browser see– to help you work this out. Is this site online?

    Thread Starter irislely

    (@irislely)

    No in fact it doesn’t work. Still have a lot to learn about using selectors. And it is not online yet, I was planning to do that tomorrow or so

    But offline, Firebug shows me this (menu item and one child):

    <li id="menu-item-65" class="menu-item menu-item-type-post_type menu-item-object-page">
    <a title="Vini" href="https://localhost/here/?page_id=63">
    Wijnen
    <span class="sub">Vini</span>
    </a>
    <ul class="sub-menu">
    <li id="menu-item-77" class="menu-item menu-item-type-post_type menu-item-object-page">
    <a title="Bollicine e vini frizzanti" href="https://localhost/here/?page_id=12">
    Bubbels en mousserende wijnen
    <span class="sub">Bollicine e vini frizzanti</span>
    </a>
    </li>

    The walker created a <span> called .sub for the description field in WP Admin. My menu is #access and I noticed a line in the functions.php saying $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>'; but that might not be of importance?

    Right now it shows the menu item and when I hover over it, it attaches the translation right next to the initial word. So I’m only looking for a line to tell the css to hide/stop displaying the menu-item.

    Does that help in anyway?

    Hard to do without being able to play with it but…

    Try putting display:block;position:relative and a height (width too if you can) on your anchors. Then put display:block;position:absolute;top:0;left:0; and the same height (and width if possible) on that span as on the anchor.

    Thread Starter irislely

    (@irislely)

    I’ve tried your suggestion but I don’t think I’m doing it right. I did manage to upload my site though:
    https://www.disiri.com/here/

    Two problems:
    1. my walker seems to have moved my menu to the left (I think it removed the container or something?) and “Home” floats outside the menu row now.
    2. my menu-item is still showing on hover. Maybe you can play around with my css?
    OR
    I was also reading https://www.nimblehost.com/blog/2012/04/multi-lingual-hover-menu/ which does exactly what I want but only in HTML. Since I created a span for the description using a walker, do you think I can add something to that walker to create a span for menu-item-? This would make it much easier in CSS, I guess.

    Thread Starter irislely

    (@irislely)

    btw. For now I only added descriptions to the second menu item so don’t worry if you don’t see anything in the other ones.

    You didn’t do quite what I said.

    #access ul li a:hover span.sub {
    display:block;
    position:absolute;
    top:0;
    left:0;
    background: <whatever that gray color is>

    You also need to set a height of about 50px and a width– width:100% almost does it.

    Once you get those changes you should have a “proof of concept” working, then just tweak the margins, paddings, whatever to get the layout right.

    Thread Starter irislely

    (@irislely)

    Thank you so much S_ha_dum! That worked! I actually did what you suggested but I had a version problem when uploading to the webserver and had to use an other css.
    I’ll do some playing around to get it all in it’s place.

    Thanks again and I wish you a good day and week!

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Title attributes to change menu on mouseover?’ is closed to new replies.