Navbarのドロップダウンメニューをphpを使って書き替えたいです。
今の状況はドロップダウンができるようにPHPで書いても
副項目も表示されてしまっています。
何もしていない状態だと親だけが表示され、hoverもしくはアイコンをクリックすると副項目が表視されるようにしたいです。
こちらがベースとなっているhtmlです。
html
1<!doctype html> 2<html lang="ja"> 3 <head> 4 <!-- Required meta tags --> 5 <meta charset="utf-8"> 6 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> 7 8 <!-- Bootstrap CSS --> 9 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous"> 10 11 <link rel="stylesheet" href="style.css"> 12 <title>aaaa</title> 13 14 15 </head> 16 <body> 17 <nav class="navbar navbar-expand-lg navbar-light bg-light"> 18 <a class="navbar-brand" href="#">Navbar</a> 19 <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> 20 <span class="navbar-toggler-icon"></span> 21 </button> 22 23 <div class="collapse navbar-collapse" id="navbarSupportedContent"> 24 <ul class="navbar-nav mr-auto"> 25 <li class="nav-item dropdown"> 26 <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> 27 Dropdown 28 </a> 29 <div class="dropdown-menu" aria-labelledby="navbarDropdown"> 30 <a class="dropdown-item" href="#">Action</a> 31 <a class="dropdown-item" href="#">Another action</a> 32 <div class="dropdown-divider"></div> 33 <a class="dropdown-item" href="#">Something else here</a> 34 </div> 35 </li> 36 <li class="nav-item"> 37 <a class="nav-link disabled" href="#">Disabled</a> 38 </li> 39 </ul> 40 </div> 41 </nav> 42 43 <!-- Optional JavaScript --> 44 <!-- jQuery first, then Popper.js, then Bootstrap JS --> 45 <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script> 46 <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> 47 <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script> 48 49 </body> 50</html>
PHPに書き換えるとドロップダウンメニューが記入できなくなってしまいます。
functions.phpになります。
php
1<?php 2/* Menu Functions */ 3register_nav_menus( 4 array( 5 'global-navigation' => 'グローバル', 6 ) 7);
index.phpになります。
php
1<!doctype html> 2<html lang="ja"> 3 <head> 4 <!-- Required meta tags --> 5 <meta charset="utf-8"> 6 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> 7 8 <!-- Bootstrap CSS --> 9 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous"> 10 11 <link rel="stylesheet" href="style.css"> 12 <title>aaaa</title> 13 14 15 </head> 16 <body> 17 <nav class="navbar navbar-expand-lg navbar-light bg-dark"> 18 <a class="navbar-brand" href="#">Navbar</a> 19 <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> 20 <span class="navbar-toggler-icon"></span> 21 </button> 22 23 <div class="collapse navbar-collapse" id="navbarSupportedContent"> 24 <div class="collapse navbar-collapse" id="navbarNav"> 25 <?php 26 $defaults = array( 27 'menu_class' => 'navbar-nav', 28 'container' => 'false', 29 'link_before' => '<span class="text-white nav-link mr-3">', 30 'link_after' => '<span>', 31 'theme_location' => 'global-navigation', 32 ); 33 wp_nav_menu( $defaults ); 34 ?> 35 </div> 36 </div> 37 </nav> 38 39 40 <!-- Optional JavaScript --> 41 <!-- jQuery first, then Popper.js, then Bootstrap JS --> 42 <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script> 43 <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> 44 <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script> 45 46 47 </body> 48</html>
css
1/* 2Theme Name: aaaa 3Theme URI: 4Description: 5Version: 1 6Author: aaaa 7Author URI: 8*/ 9 10 11
あなたの回答
tips
プレビュー