Walker_Nav_Menu: Items not nested correctly
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
I want to add "anchor" tag adjacent to every "list item" that has children.
this is my Walker_Nav_Menu class:
class Menu_Walker extends Walker_Nav_Menu {
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 )
$ident = str_repeat( "t", $depth );
if ( $args->walker->has_children )
$classes = 'menu-item-has-children menu-item menu-item-' . $item->ID;
// actual link
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";
// added tag after
$output .= "<a class="added" href="#">txt</a>";
else
$classes = 'menu-item menu-item-' . $item->ID;
// actual link
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";
This is the structure of the menu in WordPress:
But the output is not nested correctly as you can see in image below:
Please help me fix this problem
menus
New contributor
Rozo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
2
down vote
favorite
I want to add "anchor" tag adjacent to every "list item" that has children.
this is my Walker_Nav_Menu class:
class Menu_Walker extends Walker_Nav_Menu {
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 )
$ident = str_repeat( "t", $depth );
if ( $args->walker->has_children )
$classes = 'menu-item-has-children menu-item menu-item-' . $item->ID;
// actual link
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";
// added tag after
$output .= "<a class="added" href="#">txt</a>";
else
$classes = 'menu-item menu-item-' . $item->ID;
// actual link
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";
This is the structure of the menu in WordPress:
But the output is not nested correctly as you can see in image below:
Please help me fix this problem
menus
New contributor
Rozo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Of course they’re not nested correctly. You close li tag in your start_el, so how could they be correct ;)
– Krzysiek Dróżdż
2 hours ago
1
@Krzysiek Dróżdż omg you're correct, I was trying to solve this problem for the last 2 hours, removing the li closing tag solved it thank you so much.
– Rozo
2 hours ago
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I want to add "anchor" tag adjacent to every "list item" that has children.
this is my Walker_Nav_Menu class:
class Menu_Walker extends Walker_Nav_Menu {
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 )
$ident = str_repeat( "t", $depth );
if ( $args->walker->has_children )
$classes = 'menu-item-has-children menu-item menu-item-' . $item->ID;
// actual link
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";
// added tag after
$output .= "<a class="added" href="#">txt</a>";
else
$classes = 'menu-item menu-item-' . $item->ID;
// actual link
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";
This is the structure of the menu in WordPress:
But the output is not nested correctly as you can see in image below:
Please help me fix this problem
menus
New contributor
Rozo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I want to add "anchor" tag adjacent to every "list item" that has children.
this is my Walker_Nav_Menu class:
class Menu_Walker extends Walker_Nav_Menu {
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 )
$ident = str_repeat( "t", $depth );
if ( $args->walker->has_children )
$classes = 'menu-item-has-children menu-item menu-item-' . $item->ID;
// actual link
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";
// added tag after
$output .= "<a class="added" href="#">txt</a>";
else
$classes = 'menu-item menu-item-' . $item->ID;
// actual link
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";
This is the structure of the menu in WordPress:
But the output is not nested correctly as you can see in image below:
Please help me fix this problem
menus
menus
New contributor
Rozo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Rozo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 1 hour ago
Krzysiek Dróżdż
11.7k42637
11.7k42637
New contributor
Rozo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 2 hours ago
Rozo
132
132
New contributor
Rozo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Rozo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Rozo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Of course they’re not nested correctly. You close li tag in your start_el, so how could they be correct ;)
– Krzysiek Dróżdż
2 hours ago
1
@Krzysiek Dróżdż omg you're correct, I was trying to solve this problem for the last 2 hours, removing the li closing tag solved it thank you so much.
– Rozo
2 hours ago
add a comment |Â
Of course they’re not nested correctly. You close li tag in your start_el, so how could they be correct ;)
– Krzysiek Dróżdż
2 hours ago
1
@Krzysiek Dróżdż omg you're correct, I was trying to solve this problem for the last 2 hours, removing the li closing tag solved it thank you so much.
– Rozo
2 hours ago
Of course they’re not nested correctly. You close li tag in your start_el, so how could they be correct ;)
– Krzysiek Dróżdż
2 hours ago
Of course they’re not nested correctly. You close li tag in your start_el, so how could they be correct ;)
– Krzysiek Dróżdż
2 hours ago
1
1
@Krzysiek Dróżdż omg you're correct, I was trying to solve this problem for the last 2 hours, removing the li closing tag solved it thank you so much.
– Rozo
2 hours ago
@Krzysiek Dróżdż omg you're correct, I was trying to solve this problem for the last 2 hours, removing the li closing tag solved it thank you so much.
– Rozo
2 hours ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
You have this problem, because of your code ;)
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 )
$ident = str_repeat( "t", $depth );
if ( $args->walker->has_children )
$classes = 'menu-item-has-children menu-item menu-item-' . $item->ID;
// actual link
// you SHOULDN'T close the li tag in here
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";
// added tag after
$output .= "<a class="added" href="#">txt</a>";
else
$classes = 'menu-item menu-item-' . $item->ID;
// actual link
// you SHOULDN'T close the li tag in here
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";
In your start_el
you close the li
tag, so children can't be printed inside of it...
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
You have this problem, because of your code ;)
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 )
$ident = str_repeat( "t", $depth );
if ( $args->walker->has_children )
$classes = 'menu-item-has-children menu-item menu-item-' . $item->ID;
// actual link
// you SHOULDN'T close the li tag in here
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";
// added tag after
$output .= "<a class="added" href="#">txt</a>";
else
$classes = 'menu-item menu-item-' . $item->ID;
// actual link
// you SHOULDN'T close the li tag in here
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";
In your start_el
you close the li
tag, so children can't be printed inside of it...
add a comment |Â
up vote
2
down vote
accepted
You have this problem, because of your code ;)
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 )
$ident = str_repeat( "t", $depth );
if ( $args->walker->has_children )
$classes = 'menu-item-has-children menu-item menu-item-' . $item->ID;
// actual link
// you SHOULDN'T close the li tag in here
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";
// added tag after
$output .= "<a class="added" href="#">txt</a>";
else
$classes = 'menu-item menu-item-' . $item->ID;
// actual link
// you SHOULDN'T close the li tag in here
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";
In your start_el
you close the li
tag, so children can't be printed inside of it...
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
You have this problem, because of your code ;)
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 )
$ident = str_repeat( "t", $depth );
if ( $args->walker->has_children )
$classes = 'menu-item-has-children menu-item menu-item-' . $item->ID;
// actual link
// you SHOULDN'T close the li tag in here
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";
// added tag after
$output .= "<a class="added" href="#">txt</a>";
else
$classes = 'menu-item menu-item-' . $item->ID;
// actual link
// you SHOULDN'T close the li tag in here
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";
In your start_el
you close the li
tag, so children can't be printed inside of it...
You have this problem, because of your code ;)
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 )
$ident = str_repeat( "t", $depth );
if ( $args->walker->has_children )
$classes = 'menu-item-has-children menu-item menu-item-' . $item->ID;
// actual link
// you SHOULDN'T close the li tag in here
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";
// added tag after
$output .= "<a class="added" href="#">txt</a>";
else
$classes = 'menu-item menu-item-' . $item->ID;
// actual link
// you SHOULDN'T close the li tag in here
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";
In your start_el
you close the li
tag, so children can't be printed inside of it...
answered 1 hour ago
Krzysiek Dróżdż
11.7k42637
11.7k42637
add a comment |Â
add a comment |Â
Rozo is a new contributor. Be nice, and check out our Code of Conduct.
Rozo is a new contributor. Be nice, and check out our Code of Conduct.
Rozo is a new contributor. Be nice, and check out our Code of Conduct.
Rozo is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f316299%2fwalker-nav-menu-items-not-nested-correctly%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Of course they’re not nested correctly. You close li tag in your start_el, so how could they be correct ;)
– Krzysiek Dróżdż
2 hours ago
1
@Krzysiek Dróżdż omg you're correct, I was trying to solve this problem for the last 2 hours, removing the li closing tag solved it thank you so much.
– Rozo
2 hours ago