Jquery Slide down Not working for ul li structure - php

i have ul li structure like below
<ul class="lft_mnu" id="menu-main-menu">
<li class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-261 current_page_item menu-item-276" id="menu-item-276">
COMPANY HISTORY
<ul class="sub-menu">
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-287" id="menu-item-287">
Sample 1</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-286" id="menu-item-286">
Sample 2</li>
</ul>
</li>
</ul>
i am using below javascript for showing the li sub tab ul with classname sub-menu
<script type="text/javascript">
$('li.menu-item').mousehover(function () {
$('ul.sub-menu').slideDown('medium');
});
$('li.menu-item').mouseleave(function(){
$('ul.sub-menu').slideUp('medium');
});
</script>
i need to show <ul classname="sub-menu"> when i mousehover on <li classname="menu-item"> .
How can i do this?...

Try this:
<script type="text/javascript">
$(function(){
$('li.menu-item ul.sub-menu').hide();
$('li.menu-item').hover(function () {
$('ul.sub-menu', this).slideDown('medium');
}, function(){
$('ul.sub-menu', this).slideUp('medium');
});
});
</script>

One thing that you can change is there is no event like mousehover you need to change it to mouseover. The other thing that you need to note is that your child LI's are also having class menuItem so when the mouse mouses over them there also you will see the sliding behaviour which you might not want. Please check and then you might need to do some more modifications.

Related

Add icons to wordpress menu

I have some problems with Wordpress.. I tried to add icons from Wordpress -> Appearance -> Menu and it works but they are not clickable. I also want to remove the text from the menu icon and add it to "data-tooltip". And the last question is: How to add the menu item icons in a different element (not the "li" element) for example "span"?
My code should be:
<ul class="clear-list">
<li>
<span class="crt-icon crt-icon-home"></span>
</li>
<li>
<span class="crt-icon crt-icon-portfolio"></span>
</li>
<li>
<span class="crt-icon crt-icon-references"></span>
</li>
<li>
<span class="crt-icon crt-icon-contact"></span>
</li>
</ul>
But it actually looks like:
<ul id="menu-main-menu" class="clear-list">
<li id="menu-item-60" class="crt-icon crt-icon-home menu-item menu-item-type-post_type menu-item-object-page menu-item-home current-menu-item page_item page-item-7 current_page_item menu-item-60">Home
</li>
<li id="menu-item-55" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-55">Experience
</li>
<li id="menu-item-54" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-54">Portfolio
</li>
<li id="menu-item-58" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-58">Testimonials
</li>
<li id="menu-item-53" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-53">Contacts
</li>
</ul>
I hope you can help me! :)
Add icons: easiest way is to add icons via CSS.
You can to add class for each link in admin and to add icon as pseudo-element, for example if your icon is image:
.crt-icon a:after {
background: url(https://www.iconfinder.com/data/icons/ionicons/512/icon-ios7-contact-512.png);
background-size: cover;
content: '';
display: block;
height: 15px;
width: 15px;
}
If your icon is font-family - you can add it in 'content' CSS rule.
Add tooltip and remove text: you can do it with jquery:
$( '#menu-main-menu a' ).each( function () {
$( this ).attr( 'data-tooltip', $( this ).text() ).empty();
})

Wordpress Navigation Walker change ul, li for div and anchor tags

I am trying to create a custom markup for my WordPress menu, when I add a menu in WordPress, the HTML that shows is as follows:
<div class="menu-menu-container">
<ul id="menu-menu" class="menu">
<li id="menu-item-13" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-13">
Home
</li>
<li id="menu-item-14" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-14">
Another Sample
</li>
<li id="menu-item-15" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-15">
Sample Page
<ul class="sub-menu">
<li id="menu-item-22" class="menu-item menu-item-type-post_type menu-item-object-post menu-item-22">
Hello world!
</li>
</ul>
</li>
</ul>
</div>
I'm trying to change the code so that it will display using the anchor and div tags instead of ul and li. This is to work with the Bulma framework.
Normal link code:
<a class="navbar-item" href="#">Home</a>
Dropdown link code:
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link" href="#">Sample Page</a>
<div class="navbar-dropdown">
<a class="navbar-item" href="#">Sample Link</a>
</div>
</div>
Another reason I am trying to do this is to remove all of the unnecessary class and id attributes that WordPress automatically adds.
Is this possible with WordPress by using a walker?
Yes it is, you can use
https://github.com/wp-bootstrap/wp-bootstrap-navwalker (most common)
You can also check
1) https://github.com/wp-bootstrap/wp-bootstrap-navlist-walker
2) https://github.com/jprieton/wp-bootstrap4-navwalker
3) https://github.com/dupkey/bs4navwalker

Edit HTML of a wordpress menu

i want to change the default HTML of wordpress's nav in a my custom theme adding a caret in the li that has a sub menu.
The default html looks like:
<ul id="menu-menu" class="nav navbar-nav">
<li id="menu-item-98" class="classes">Normal item</li>
<li id="menu-item-105" class="classes menu-item-has-children dropdown">Has a sub menu
<ul class="sub-menu">
<li id="menu-item-113" class="classes">Sub menu item</li>
</ul>
</li>
</ul>
And I havo to change this in this form:
<ul id="menu-menu" class="nav navbar-nav">
<li id="menu-item-98" class="classes">Normal item</li>
<li id="menu-item-105" class="classes menu-item-has-children dropdown">
<a href="#">
Has a sub menu
<!-- ADD THIS PART -->
<span class="caret"></span>
</a>
<ul class="sub-menu">
<li id="menu-item-113" class="classes">Sub menu item</li>
</ul>
</li>
</ul>
I think that it's possible do something like this with php in function.php but I don't know how. Can you help me? Thanks in advice.
Add your submenu under Appearance --> Menus.
Then, you can use the Chrome/Firebug inspector to find the class/id of the UL for the submenu(s) you would like to add the caret to. Modify your child theme's style.css with something like the following:
ul .sub-menu {
list-style-image: url('caret.gif');
}

jquery hide or show dynamic li of ul when click on li

In php while loop i got this type of data and when i click on li which id="test1" then hide that li which id="test1" and show li which id="new_test1"
i want to for particular ul means i click "li" then do process for that particular ul in which that li is present.
<ul id="cpvote">
<li id="test1">Message 1</span></li>
<li id="test2">Message 2</li>
<li id="test3">Message 3</li>
<li id="new_test1" style="display:none">Message 4</li>
<li id="new_test2" style="display:none">Message 5</li>
</ul>
<ul id="cpvote">
<li id="test1">Message 1</span></li>
<li id="test2">Message 2</li>
<li id="test3">Message 3</li>
<li id="new_test1" style="display:none">Message 4</li>
<li id="new_test2" style="display:none">Message 5</li>
</ul>
<ul id="cpvote">
<li id="test1">Message 1</span></li>
<li id="test2">Message 2</li>
<li id="test3">Message 3</li>
<li id="new_test1" style="display:none">Message 4</li>
<li id="new_test2" style="display:none">Message 5</li>
</ul>
IDs must be unique. However you can use a class multiple times.
Use class selector. Following is just an example to achieve desired result using class selector
HTML:
<ul class="cpvote">
<li class="test1">Message 1</li>
<li class="new_test1" style="display:none">Message 4</li>
</ul>
<ul class="cpvote">
<li class="test1">Message 1</li>
<li class="new_test1" style="display:none">Message 4</li>
</ul>
<ul class="cpvote">
<li class="test1">Message 1</li>
<li class="new_test1" style="display:none">Message 4</li>
</ul>
Script:
$(document).ready(function () {
$(document).on('click', '.cpvote .test1', function () {
$(this).closest('.cpvote').find('.new_test1').toggle();
});
});
DEMO
Try to do like this.
by using Jquery make UL Unique Identified
$( document ).ready(function() {
// putting extra unique attributes in UL to Identified.
$("UL").each(function(i){
$("UL").eq(i).attr('ul-id','ul-'+i);
});
$("UL").each(function(i){
$("UL[ul-id='ul-"+i+"']").find("LI").on("click",function(){
$("UL[ul-id='ul-"+i+"']").find("#new_"+$(this).attr('id')).show();
});
});
});
DEMO : http://jsfiddle.net

Regular Expression Function does not match an item

Can someone please help me? I have this php regex function:
preg_replace_callback('/(<li[^>]+class=")([^"]+)("?[^>]+>[^>]+>)([^<]+)<\/a>/')
and I want it to match this string (which is a BootStrap Navbar Group Item):
<li id="menu-item-63" class="fa-home menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-63 dropdown open"><a title="Menu" href="#" data-toggle="dropdown" class="dropdown-toggle" aria-haspopup="true">Menu <span class="caret"></span></a>
<ul role="menu" class=" dropdown-menu">
<li id="menu-item-53" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-53"><a title="Multiple Paragraph Page" href="http://localhost:8888/point/?page_id=33">Multiple Paragraph Page</a></li>
<li id="menu-item-52" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-52"><a title="Grandchild Page" href="http://localhost:8888/point/?page_id=40">Grandchild Page</a></li>
<li role="presentation" class="divider"></li>
<li id="menu-item-51" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-51"><a title="Child Page" href="http://localhost:8888/point/?page_id=39">Child Page</a></li>
</ul>
</li>
The function currently works for non group items, like this. But I want it to also include the first LI item above. What the rest of the script then does is, it adds the FontAwesome classes and modifies the Link Text like below:
<li id="menu-item-46" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-46">
<a title="Headers Page" href="http://localhost:8888/point/?page_id=38">
<i class="fa-home fa"></i>
<span class="fontawesome-text"> Headers Page</span>
</a>
</li>
Any help would be much appreciated!
also, here is the complete code from where I got the regex function from: http://pastebin.com/nQttGRnr
I gave up on trying to utilize this script. I figured my problem was that I tried to use the WP Nav Menu Settings Classes, whereas Title Attribute worked without problems!

Categories