Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将静态导航菜单更改为wordpress动态菜单_Php_Html_Css_Wordpress - Fatal编程技术网

Php 将静态导航菜单更改为wordpress动态菜单

Php 将静态导航菜单更改为wordpress动态菜单,php,html,css,wordpress,Php,Html,Css,Wordpress,我正在尝试将我的静态导航菜单转换为WP动态导航 这就是我得到的: <nav> <ul id="menu"> <?php $pages = array( 'index.php' => 'Home', 'services.php' => 'Services', 'sitemap.php' => 'Calculators', 'about.php' => '

我正在尝试将我的静态导航菜单转换为WP动态导航

这就是我得到的:

     <nav>
         <ul id="menu">

            <?php 


                $pages = array( 'index.php' => 'Home', 'services.php' => 'Services', 'sitemap.php' => 'Calculators', 'about.php' => 'About'
                , 'contact.php' => 'Contact' );

                $query = $_SERVER['PHP_SELF'];
                    $path = pathinfo( $query );
                    $selected = $path['basename'];

                foreach( $pages as $url => $title ) {
                   $li = '<li ';
                   if( $url === 'index.php' ) {
                       $li .= 'class="alpha"';
                   } else if ( $url === 'contact.php' ){
                       $li .= 'class="omega"';
                   }

                   if( $selected == $url ) {
                       $li .= 'id="menu_active"';
                   }
                   $li .= '><a href="' . $url . '"><span><span>' . $title . '</span></span></a></li>';
                   echo $li;
                }
            ?>

        </ul>
    </nav>

但我读到我需要用这个

                    <?php wp_nav_menu( array( 
                        'theme_location' => 'primary',
                        'container' => false,
                        'menu_class' => 'menu'
                    ) ); ?>

我真的不明白,也不知道如何实现这一点?有什么想法吗?我真的被这件事困住了,所以非常需要帮助,非常感激。谢谢。

您可以尝试以下方法:

            <?php
            $defaults = array(
                'theme_location'  => '',
                'menu'            => '',
                'container'       => false,
                'container_class' => '',
                'container_id'    => '',
                'menu_class'      => 'menu',
                'menu_id'         => '',
                'echo'            => true,
                'fallback_cb'     => 'wp_page_menu',
                'before'          => '',
                'after'           => '',
                'link_before'     => '',
                'link_after'      => '',
                'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
                'depth'           => 2,
                'walker'          => ''
                );
            wp_nav_menu( $defaults );
            ?>
wp_nav_menu( array( 'container' => 'ul', 'menu_class' => 'menu', 'depth' => 2,'theme_location' => 'primary' ));
并在functions.php中编写以下代码:

if ( ! function_exists( 'nav_setup' ) ):
function nav_setup() {

// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
    'primary' => __( 'Primary Navigation', 'StreetCoder' ),
) );

}
尝试使用firebug,您会在li标签中找到一些类,即
当前菜单项
子菜单
中的
li ul li
当前菜单父项
中的父项
,单击子项后,
当前菜单父项
中的子项等。将css属性转移到这些类中

此外,如果您想为特定的li包含特定的类,请转到
外观>菜单
,您将在右上角找到一个选项,即“屏幕选项”,单击此处。面板将展开,然后选中“显示高级菜单属性”下的“CSS类”选项。现在,当您从右面板展开菜单时,您将发现一个输入字段“CSS类(可选)”。只需为特定的li设置特定的类。 小组


我希望这就是菜单的全部功能。:)

嗯,谢谢,但我的问题是
  • 标记,我有像menu\u active class alpha和omegaWordpress这样的ID添加了自己的活动类-使用它们。@ChrisHerbert我如何使用活动类?当前菜单项
  • 将有类
    。当前菜单项
    。提出问题前,请先查阅法典
    
    // register this menu to function.php<br>
    register_nav_menu( 'top', __( 'Top Menu', 'themify' ) );
    
    //call menu to header.php<br>
    <div class="top-header">
    
        if (has_nav_menu('top')) {<br>
          wp_nav_menu( array('theme_location' => 'top' ) );<br>
         }
    
    </div>