dongshushen4392
2015-05-28 14:15
浏览 101
已采纳

自定义css在顶部导航为特定页面wordpress

I am new to wordpress theme development and I need to style the main navigation menu depending on what page the user is on.

Simply put, only the home page has a unique styling on it and all other pages will have a different css. I have tried adding this in my functions.php but it does not work.

if (is_page( 52 ) ):
    wp_enqueue_style('style1_css', get_template_directory_uri() . '/css/style1.css' );
endif;

Sorry if its badly explained!

图片转代码服务由CSDN问答提供 功能建议

我是wordpress主题开发的新手,我需要根据用户所在的页面设置主导航菜单的样式 。

简单地说,只有主页上有独特的样式,所有其他页面都有不同的CSS。 我已尝试在我的functions.php中添加它,但它不起作用。

  if(is_page(52)):
 wp_enqueue_style('style1_css',get_template_directory_uri()。  '/css/style1.css'); 
endif; 
   
 
 

很抱歉,如果解释得不好!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • douhuang2218 2015-05-29 07:24
    已采纳
    fixed it by adding
    

    nav <?php if ( is_page('52')) { echo 'class="homeNav"'; } ?>>

    </div>
    
    点赞 打赏 评论
  • dongzao4503 2015-05-28 14:23
    <?php // TOP PICTURE DEFINITION FOR ARTICLES PAGE
            if ( is_page()) {
               wp_enqueue_style('style1_css', get_template_directory_uri() . '/css/style1.css' );
            }
    ?>
    

    Use like this for detailed reference kindly refer this link click_here

    点赞 打赏 评论
  • dongyu6276 2015-05-28 14:38

    You can link one css file for all pages and use more specific selectors (with binging to css-classes) for css ruling:

      .nav {/* for all pages */
        ...
      }
     
      .home .nav { /* for home page */
        ...
      }

    </div>
    
    点赞 打赏 评论
  • dongpanshi2839 2015-05-28 18:39

    Target only the home class like:

    .home .nav { 
     // CSS STUFF
    }
    

    And if you want all nav classes, use:

    .nav { 
     // CSS STUFF
    }
    
    点赞 打赏 评论

相关推荐 更多相似问题