2017-03-20 190 views
1

我为我的WordPress的网站使用景观主题(https://en-gb.wordpress.org/themes/landscape/)。 问题是,当我需要的是中殿酒吧菜单时,标题叠加图像被附加到导航栏菜单。在主页上没问题,但它也出现在其他所有页面上,这是不必要的。 我试图用一个if条件:WordPress的 - 如何删除标题覆盖

<?php if (is_home()) { ?> 
    <div class="header-overlay"> 
    <div class="site-branding"> 
     <h1 class="site-title"><a href="<?php echo esc_url(home_url('/')); ?>" rel="home"><?php bloginfo('name'); ?></a></h1> 
     <h2 class="site-description"><?php bloginfo('description'); ?></h2> 
     </div> 
    </div> 
<?php } ?> 

但没有奏效。

任何人都可以帮助如何从代码中删除它?

的header.php:

<body <?php body_class(); ?>> 
    <div id="page" class="hfeed site"> 

    <div class="site-branding"> 
    <a href="http://localhost/abba_property_services/"><img src="http://localhost/abba_property_services/wp-content/uploads/2017/03/ABBA-Solutions-White-Background-1.png"></a> 
    </div> 
    <a class="skip-link screen-reader-text" href="#content"><?php esc_html_e('Skip to content', 'landscape'); ?></a> 

    <header id="masthead" class="site-header" role="banner"> 
    <nav role="navigation" class="site-navigation main-navigation"> 
     <h1 class="assistive-text"><?php _e('Menu', 'landscape'); ?></h1> 

     <?php wp_nav_menu(array('theme_location' => 'primary')); ?> 
    </nav><!-- .site-navigation .main-navigation --> 

    <div class="header-overlay"> 
     <div class="site-branding"> 
      <h1 class="site-title"><a href="<?php echo esc_url(home_url('/')); ?>" rel="home"><?php bloginfo('name'); ?></a></h1> 
      <h2 class="site-description"><?php bloginfo('description'); ?></h2> 
     </div> 
    </div> 
    </div> 
</header> 

enter image description here

的header.php

回答

1

添加

<header <?php if (is_home()) { echo 'id="masthead"'; }?>class="site-header" role="banner"> 

改变CSS

.site-header { 
height: auto; 
} 
.home .site-header { 
height: 40.625rem; 
} 
+0

这工作就像一个魅力!非常感谢! –

+0

还有一个空白区域,标题叠加图像将位于所有其他页面上。有没有办法摆脱它? –

+0

@ T.Doe你为什么要删除你的问题?我想回答它..): –

0

图像背景调用实际上是在#masthead规则中,但它被挂钩到定制器中,因此您可以轻松地将其从中移除。问题是空间仍然会被占用,因此您需要对CSS进行一些调整,使其仅在主页上使用.home类定义。

+0

那是正确的!我目前正面临着一个巨大的空白空间.header-pverlay {display:none;没有工作。你有这样的代码示例吗? –