adding parent link to submenu
menu a link to its parent, for example:
I have the following menu:
Parent 1
- Child 1
- Child 2
- Child 3
I wish to add to it (on the fly, not throw the wordpress cms) link to the parent:
Parent 1
- Parent 1
- Child 1
- Child 2
- Child 3
I've searched a lot but got only to this piece of code and I do not know how to continue:
/* Duplicate the parent in a menu */
add_filter( 'wp_nav_menu_objects', 'duplicate_parents' , 10 , 2 );
add_filter( 'wp_nav_menu_items' , 'duplicate_parents' );
function hasSub($menu_item_id, &$items) {
foreach ($items as $item)
{
if ($item->menu_item_parent && $item->menu_item_parent==$menu_item_id)
{
return true;
}
}
return false;
}
$menu_item_parents = array();
function duplicate_parents( $items , $args ) {
if ( !($args->duplicate_parents) )
return ($items);
foreach ($items as $item)
{
if ( hasSub($item->ID, &$items) )
{
// here I have the parent object, but I do
// not know how to add to it data.
}
}
return ($items);
}
menu a link to its parent, for example:
I have the following menu:
Parent 1
- Child 1
- Child 2
- Child 3
I wish to add to it (on the fly, not throw the wordpress cms) link to the parent:
Parent 1
- Parent 1
- Child 1
- Child 2
- Child 3
I've searched a lot but got only to this piece of code and I do not know how to continue:
/* Duplicate the parent in a menu */
add_filter( 'wp_nav_menu_objects', 'duplicate_parents' , 10 , 2 );
add_filter( 'wp_nav_menu_items' , 'duplicate_parents' );
function hasSub($menu_item_id, &$items) {
foreach ($items as $item)
{
if ($item->menu_item_parent && $item->menu_item_parent==$menu_item_id)
{
return true;
}
}
return false;
}
$menu_item_parents = array();
function duplicate_parents( $items , $args ) {
if ( !($args->duplicate_parents) )
return ($items);
foreach ($items as $item)
{
if ( hasSub($item->ID, &$items) )
{
// here I have the parent object, but I do
// not know how to add to it data.
}
}
return ($items);
}
No comments:
Post a Comment