【问题标题】:I can't style my customized menu in my wordpress website我无法在我的 wordpress 网站中设置自定义菜单的样式
【发布时间】:2014-02-16 20:52:15
【问题描述】:

我在首先创建我的网站时遇到了这个问题,我的 header.php 页面中有一个菜单。 然后我想把我的网站变成一个wordpress网站,所以我做了我必须做的事情,但问题是我仍然想不出一种方法来将header.php中的导航菜单转换成一个可以工作的菜单在 wordpress 上。

我已经尝试了 wordpress 教程以及一些论坛提供的所有解决方案,但我尝试的所有方法都会在我想要的菜单之上创建一个丑陋的菜单,甚至无法点击。

我能够创建一个菜单位置或任何其他位置,当我在仪表板中创建菜单时,我在所需菜单的顶部得到了这个创建的菜单。当我将鼠标悬停在我想要的菜单上时(在以下代码中:main_menu),甚至没有任何反应。

这是我的 header.php:

    <?php
/**
 * The Header template for our theme
 *
 * Displays all of the <head> section and everything up till <div id="main">
 *
 * @package WordPress
 * @subpackage Twenty_Thirteen
 * @since Twenty Thirteen 1.0
 */
?><!DOCTYPE html>

<!--[if IE 7]>
<html class="ie ie7" <?php language_attributes(); ?>>
<![endif]-->
<!--[if IE 8]>
<html class="ie ie8" <?php language_attributes(); ?>>
<![endif]-->
<!--[if !(IE 7) | !(IE 8)  ]><!-->
<html <?php language_attributes(); ?>>
<!--<![endif]--><head>
<?php /* Get our main menu Navigation bar */ ?>
<?php get_template_part( 'navigation', 1 ); ?>
<?php /* Get our top menu Navigation bar */ ?>
<?php get_template_part( 'navigation', 2 ); ?>


<?php wp_nav_menu( array( 'theme_location' => 'header-menu', 'container_class' => 'main_menu' ) ); ?>


    <meta charset="<?php bloginfo( 'charset' ); ?>">
    <meta name="viewport" content="width=device-width">
    <title><?php wp_title( 'entendrelimage', true, 'right' ); ?></title>
    <link rel="profile" href="http://www.entendrelimage.univ-paris1.fr/‎">
    <link rel="pingback" href="<?php bloginfo( 'entendrelimage_url' ); ?>">
    <!--[if lt IE 9]>
    <script src="<?php echo get_template_directory_uri(); ?>/js/html5.js"></script>
    <![endif]-->
    <?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>
        <header>
        <div id="main_menu">
        <nav>
            <ul>
                <li><a href="#page2">Décryptage</a></li>
                <li><a href="#page3">Symboles</a></li>
            </ul>
        </nav>
        <br/ class="annuleFloat">

        <ul id="recherche">
                <li><a href="www.google.com"><img id="glo" src="<? bloginfo('stylesheet_directory'); ?>/images/glosaire_off.png" alt=""/></a></li>
                <li><img src="<? bloginfo('stylesheet_directory'); ?>/images/ligne_top_right.png"/></li>
                <li><a href="#"><img id="rech" src="<? bloginfo('stylesheet_directory'); ?>/images/recherche_off.png" alt=""/></a></li>
        </ul>
        </div>
        <div id="logo">
            <a href="#page1"><img src="<? bloginfo('stylesheet_directory'); ?>/images/logo.png" alt=""/></a>
            <br/ class="annuleFloat">
        </div>
        </header>
<!-- #masthead -->

        <div id="container">
        <div class="main">

这是我放在functions.php中的部分代码:

    function register_my_menu() {
  register_nav_menu('header-menu',__( 'Header Menu' ));
}
add_action( 'init', 'register_my_menu' );

所以如果有人能告诉我这个问题,那就太好了!我拼命地卡在这个上

【问题讨论】:

    标签: html css wordpress menu


    【解决方案1】:

    好的,我不知道我是否真的理解这个问题,但我会尽力回答并给出解决方案。基本上:在您的“第一个”(旧)网站上,您有一个菜单,现在您想在 Wordpress 中重新制作它,并对其进行样式设置,使其看起来和感觉与旧网站一样好。

    没问题。在 Wordpress 的后端,转到外观 > 菜单并创建一个新菜单。如果需要,将其命名为“header-menu”。将您在 WP 中创建的任何新页面放入其中,或者只为您想要的页面创建自定义链接(#page2、http://www.google.com 等)。

    现在回到你的 .php 页面,把这段代码放在标题中

    <?php wp_nav_menu( array( 'theme_location' => 'header-menu', 'container_class' => 'main_menu' ) ); ?>
    

    进入页面的主体(可能在主菜单 div 中?)。它输出菜单“header-menu”,因此它应该在页面 html 内。这可能导致了“看得见但不能点击”的问题。我不认为你需要弄乱functions.php中的任何东西来让菜单工作。将其放在页面上后,只需查看并设置所需的 CSS 样式即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-19
      • 2020-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多