Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(FEATURE) Semantic HTML #1

Merged
merged 1 commit into from
Mar 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions navwalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,40 @@

class Navwalker extends Walker_Nav_Menu {

public function start_lvl( &$output, $depth = 0, $args = array() ) {

$output .= "<div class='navbar-dropdown'>";
}

public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {

$liClasses = 'navbar-item '.$item->title;
$lowerCaseTitle = strtolower($item->title);
$linkTitle = str_replace(' ', '', $lowerCaseTitle);
$liClasses = 'navbar-item '.$linkTitle;

$hasChildren = $args->walker->has_children;
$liClasses .= $hasChildren? " has-dropdown is-hoverable": "";
$liClasses .= $hasChildren ? " has-dropdown is-hoverable": "";

if($hasChildren){
$output .= "<div class='".$liClasses."'>";
$output .= "\n<a class='navbar-link' href='".$item->url."'>".$item->title."</a>";
}
else {
$output .= "<a class='".$liClasses."' href='".$item->url."'>".$item->title;
}
$linkClasses = $hasChildren ? "" : "is-arrowless";

$output .= '<li class="'.$liClasses.'">';

$output .= '<a class="navbar-link '.$linkClasses.'" href="'.$item->url.'">'.$item->title.'</a>';

// Adds has_children class to the item so end_el can determine if the current element has children
if ( $hasChildren ) {
$item->classes[] = 'has_children';
$item->classes[] = "has_children";
}
}

public function end_el(&$output, $item, $depth = 0, $args = array(), $id = 0 ){

if(in_array("has_children", $item->classes)) {

$output .= "</div>";
}
$output .= "</a>";
public function start_lvl( &$output, $depth = 0, $args = array() ) {
$output .= '<ul class="navbar-dropdown">';
}

public function end_lvl (&$output, $depth = 0, $args = array()) {
$output .= "</ul>";
}

public function end_el(&$output, $item, $depth = 0, $args = array(), $id = 0 ){

$output .= "</li>";

$output .= "</div>";
}

}
?>