2016-12-24 124 views
0

我正在学习如何从头开始制作WordPress主题&我现在面临一个不好的问题。问题是我添加的CSS样式不适用于我的主题的菜单导航。我的WordPress自定义主题没有获取CSS样式

这里的index.php文件:

<?php 
get_header(); 

if (have_posts()): 
    while (have_posts()) : the_post(); ?> 

    <article class="post"> 
     <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
     <h2><?php the_content(); ?></h2> 
    </article> 

    <?php endwhile; 

    else: 
     echo '<p>No content found!</p>'; 

    endif; 

get_footer(); 
?> 

这里的header.php文件:

<!DOCTYPE html> 
<html <?php language_attributes(); ?>> 
    <head> 
     <meta charset="<?php bloginfo('charset'); ?>"> 
     <meta name="viewport" content="width=device-width"> 
     <title><?php bloginfo('name'); ?></title> 
     <?php wp_head(); ?> 
    </head> 

<body <?php body_class(); ?>> 

    <div class="container"> 
     <header class="site-header"> 
      <h1><a href="<?php echo home_url(); ?>"><?php bloginfo('name'); ?></a></h1> 
      <h5><?php bloginfo('description'); ?></h5> 

      <nav class="site-nav"> 
       <?php 
       $args = array(
        'theme_location' => 'primary' 
       ); 
       ?> 
       <?php wp_nav_menu($args); ?> 
      </nav> 
     </header> 

正如你可以看到我加入的CSS类站点导航标签,然后我将其编码为css样式:

.site-nav ul{ 
    margin:0; 
    padding:0; 
} 
.site-nav ul:before, .site-nav ul:after{content: "";display:table;} 
.site-nav ul:after{clear:both;} 
.site-nav ul{*zoom:1;} 
.site-nav ul li{ 
    list-style:none; 
    float:left; 
} 

但每当我跑的主题,我得到这个画面:

enter image description here

但请注意,我已经有functions.php它增加了CSS样式和我已经加入其他CSS样式,如身体或等来它和它的作品,但我不明白为什么菜单导航不会改变!

这里的functions.php

<?php 
function learningWordpress_resources(){ 
    wp_enqueue_style('style', get_stylesheet_uri()); 
} 
add_action('wp_enqueue_scripts','learningWordpress_resources'); 
register_nav_menus(array(
    'primary' => __('Primary Menu'), 
    'footer' => __('Footer Menu'), 
)); 
?> 

下面是完整的CSS code

+0

包括头部CSS路径,并添加样式表文件,所有的CSS。它会自动工作 – Gulshan

+0

是的style.css文件放置在您主题文件夹? – Gulshan

+0

请提供一个functions.php –

回答

1

你必须提供类

<nav class="site-nav"> 
<?php 
     $args = array(
     'theme_location' => 'primary', 
     'menu_class'  => 'site_nav', 
    ); 
    ?> 
    <?php wp_nav_menu($args); ?> 

转到检查的CSS这样

#header .site-nav{} // container class 
#header .site-nav ul {} // container class first unordered list 
#header .site-nav ul ul {} //unordered list within an unordered list 
#header .site-nav li {} // each navigation item 
#header .site-nav li a {} // each navigation item anchor 
#header .site-nav li ul {} // unordered list if there is drop down items 
#header .site-nav li li {} // each drop down navigation item 
#header .site-nav li li a {} // each drap down navigation item anchor 

的functions.php改变

add_action('after_setup_theme', 'register_my_menu'); 
function register_my_menu() { 
    register_nav_menus(array(
    'primary' => __('Primary Menu'), 
    'footer' => __('Footer Menu'), 
    )); 
} 
    add_theme_support('menus'); 

参见: http://www.wpbeginner.com/wp-themes/how-to-style-wordpress-navigation-menus/

+0

弄来的解决方案? –

+0

缺少主题支持? –