Hot answers tagged menus
3
This depends on what kind of menu you are talking about:
1)
If you are talking about "custom menus" (found in the Backend under Design -> Menus) you can do the following:
Create a new function with the action hook add_category
inside of this function, you can create a new post of type the menu
item type, which is added correctly to your menu
whenever a ...
3
The Navigation Menus system is adding a lot of classes, including matching current page (rather intelligently, it will even try to detect custom URLs, that were input explicitly).
The simplest class to make use of is current-menu-item, but there are quite a few more dealing with parents/ancestors and more.
Codex has them documented at wp_nav_menu() > Menu ...
2
Funny, I just ran into this same conundrum a few months back...
Background
I found it quite bizarre that Wordpress applies all manner of CSS classes to menu-items in order to distinguish the current item and its ancestors, but then completely ignores the sub-menus and their relationship with the current item. I wanted a .current-sub CSS class so that I ...
2
This:
if (is_tag()){
will be true for any query on a tag archive page, including the query WordPress makes to load menu items.
You want to check if the current query is both the main query and tag query:
if ($query->is_main_query() && $query->is_tag()){
2
From what I thought was a duplicate, we get a class to render the meta box in the Nav-Menus page.
Then I used this core function to render the meta box contents.
It works ok, but it's displaying some notices and may need a good cleanup. It's too much code to parse right now and I'll leave it here as starting point. The modifications I've done involve the ...
2
By inspecting the file /wp-admin/nav-menus.php we can see that these meta-boxes:
are rendered with:
<?php do_meta_boxes( 'nav-menus', 'side', null ); ?>
The file /wp-admin/includes/nav-menu.php contains the corresponding add_meta_box() calls and from that we can construct the relevant removal code:
function custom_remove() {
...
1
Basically the easiest thing should be a callback to the start_el() method of the Walker class.
// From core:
apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
Just grab the data (whatever the actual data is and from wherever it comes) and append it.
add_action( 'walker_nav_menu_start_el', 'wpse_10042_nav_menu_post_count', ...
1
Call wp_nav_menu() before wp_head() is called, and store the result for later usage:
<head>
<?php
$menu = wp_nav_menu(
array(
'echo' => FALSE,
'theme_location' => 'primary',
'walker' => new Special_Walker
)
);
wp_head();
?>
</head>
<body>
<?php
echo $menu;
Now you ...
1
You could build a custom Walker that would either not insert that on the last field or insert classes you could use, but if this is the only change you want that would be overkill. Hide it with CSS. Something like...
.menu li:last-child .navSep {
display:none;
}
I guessed at the CSS but that is the general idea.
1
I don't have the time to work out a complete solution (which could be pretty complex) but, if I am reading things right, by default WordPress uses Walker_Nav_Menu_Edit to create those backend menus. It looks to me like you can build your own walker for the backend and pass it in via the wp_edit_nav_menu_walker hook.
If you did that, you should be able to ...
1
If you want to return the output of wp_nav_menu(), instead of echo-ing it, you should replace
'echo' => 1,
with
'echo' => 0,
Then you should get something out of var_dump( $menu );.
You can read more about the input parameters in the Codex.
Update:
You should remove this line:
'items_wrap' => '',
to use the ...
1
I assume you mean on the admin bar on the front end, that show up for logged in users.
The body_class function inserts a class called admin-bar when that is present. The admin bar is 28px high. You should be able to use that body class to conditionally relocate your sticky menu.
1
Menu items are added to the left hand dashboard menu with a few different functions, depending on where you want it to display. You will probably want to use add_menu_page. The last parameter of this function will determine how far up/down it displays. These are the defaults that you can position your item around:
Positions for Core Menu Items
2 ...
1
To solve this problem i tried to create a plugin which automatically create menu item for publish category under it's parent category if in menu.
Idea for plugin:
1.in code, i used "created_$taxonomy" action hook.
2.collect all the menu item ( by using wp_get_nav_menu_items)
3.and put condition if parent of publish category lies in menu-item than a ...
1
I coded my own for one my of clients
<div class="menu">
<ul id="MenuBar1" class="MenuBarHorizontal">
<li><a <?PHP if( count($_GET) == 0 ){ echo 'class="-current"';} ?> href="<?php echo esc_url( home_url( '/' ) ); ?>">home</a></li>
<?php
$category_ids = get_all_category_ids();
...
1
I prefer using wp_list_categories. Here is my code I used in my last project:
<?php wp_list_categories('orderby=ID&exclude=3,10,1,16,38&title_li=<span class="sidebar_heading d_shadow">' . __('Categories') . '</span>'); ?>
You will get a list of all your categories and sub-categories.
1
It looks like this display: inline-table; is causing the extra space to appear at the bottom. You can fix it by adding margin: 0 0 -4px; to the item .menu-top-container ul li
I found some help information on these inline objects, here.
It seems to be used to center the menu in that navigation, but it's not supported by IE 7 and below. Maybe you can find ...
1
I'm using the following code on one of my websites:
if ( // Maybe you want different conditionals?
(is_page() && ! is_front_page())
|| is_category()
) {
$id = get_the_ID();
$ancestors = get_ancestors($id, 'page');
if (! empty($ancestors)) $id = $ancestors[count($ancestors)-1];
$subpages = ...
1
I could not find a built-in way to accomplish this solution, but I have created a workaround
I realized, if the menu won't stay open, why not open it myself?
I created the following two functions, which are easy enough to understand. They need to be called in a javascript file which is loaded via admin script (see the function wp_enqueue_script and the ...
1
If your menu includes children the following code works well (in place of the above javascript)
jQuery(document).ready(function(){
jQuery('ul:first').attr("id", "MENUID");
jQuery("ul#MENUID > li:has(ul)").addClass("hasChildren");
jQuery("ul#MENUID > li:has(ul) > ul > li > a").addClass("isChild");
});
jQuery(function() {
...
1
Modified from One Trick Pony's code as it didn't work for me with a current version of WP (3.5.1).
Added the dashed classes as WP now includes both underscored and dashed versions of the page hierarchy classes.
Changed array_diff -> array_intersect as diff returns all the classes instead of the filtered list.
// for custom menus
...
Only top voted, non community-wiki answers of a minimum length are eligible
