2017-03-20 187 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;沒有工作。你有這樣的代碼示例嗎? –