简体   繁体   English

我无法在Wordpress网站上设置自定义菜单的样式

[英]I can't style my customized menu in my wordpress website

I am having this problem where I created my website first, with a menu in my header.php page. 我遇到的这个问题是我首先在header.php页面上创建菜单时创建了我的网站。 And then I wanted to transform my website into a wordpress website, so I did what I had to do, but the problem is that I still can't figure out a way to transform the navigation menu in header.php into a menu that works on wordpress. 然后我想将我的网站转换为wordpress网站,所以我做了我必须做的,但是问题是我仍然想不出一种将header.php中的导航菜单转换为有效菜单的方法。在WordPress上。

I have tried all solutions given by the wordpress tutoriels as well as some forums, but everything I try creates an ugly menu on top of my desired menu that is not even clickable. 我已经尝试了wordpress tutoriels和一些论坛提供的所有解决方案,但是我尝试的所有操作都会在所需菜单的顶部创建一个难看的菜单,甚至无法单击。

I was able to create a menu location or whatever that is,and when I created the menu in the dashboard, I got this created menu on top of my desired menu. 我可以创建菜单位置,也可以创建菜单位置,然后在仪表板上创建菜单时,将创建的菜单放在所需菜单的顶部。 When I hover my mouse over my desired menu(in the following code: main_menu), nothing even happens. 当我将鼠标悬停在所需的菜单上时(在以下代码中:main_menu),什至没有任何反应。

Here is my header.php: 这是我的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">

and this is the part of code that I put in functions.php: 这是我放入functions.php中的代码的一部分:

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

So if anybody can tell me the problem it would be great!! 因此,如果有人可以告诉我这个问题,那就太好了!! I am desperately stuck at this one 我迫切地被困在这个

OK, I don't know if I am really understanding the issue but I will do my best to answer and give a solution. 好的,我不知道我是否真的了解这个问题,但是我会尽力回答并提供解决方案。 Basically: on your "first" (old) site, you had a menu, and now you want to remake it in Wordpress, and style it so it looks and feels as good as the old one. 基本上:在您的“第一个”(旧)站点上,您有一个菜单,现在您想在Wordpress中对其进行重新制作,并对它进行样式设置,使其外观和感觉都与旧的一样。

No problem. 没问题。 On the backend of Wordpress, go to Appearance > Menus and create a new menu. 在Wordpress的后端,转到外观>菜单,然后创建一个新菜单。 Name it "header-menu" if you want. 如果需要,可将其命名为“ header-menu”。 Put any of the new pages you've made in WP into it, or just make custom links to the pages you want (#page2, http://www.google.com , etc). 将您在WP中创建的任何新页面放入其中,或仅创建指向所需页面的自定义链接(#page2, http://www.google.com等)。

Now back on your .php page, put this code you had in the header 现在回到您的.php页面,将此代码放在标头中

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

into the main body of the page (maybe in the main-menu div?). 进入页面的主体(也许在主菜单div中?)。 It outputs the menu "header-menu" so it should be inside the page html. 它输出菜单“ header-menu”,因此它应该在页面html内。 This might have contributed to the "can see but can't click it" problem. 这可能导致了“可以看到但无法单击它”问题。 I don't think you need to mess with anything in functions.php to get a menu working. 我认为您无需弄乱functions.php中的任何内容即可使菜单正常工作。 After you have it on the page, just take a look and style the css how you want. 将其放在页面上后,只需看一下外观并设置css的样式即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM