2016-04-18 23 views
0

我在Wordpress上使用Genesis框架,並希望在URL包含特定字符串時更改徽標和主菜單。例如,如果網址爲http://example.com/testing,我希望example.com有一個徽標和菜單,當URL中有「測試」時,則需要另一個徽標和菜單。如果URL包含特定的字符串,如何更改創世Wordpress上的標誌和菜單?

從來就試過這種改變的標誌:

function new_headerimage(){ 
    if(basename($_SERVER['REQUEST_URI']) == 'testing') { 
     echo '<div class="testing-header"><a href="http://example.com/testing"><img src="http://example.com/wp-content/uploads/2016/04/logotest.jpeg" alt="logo image" /></a></div>'; 
    } else { 
     echo '<div class="original-header"><a href="http://example.com/"><img src="http://example.com/wp-content/uploads/2016/04/logotest2.jpeg" alt="logo" /></a></div>'; 
}} 
add_action('genesis_header', 'new_headerimage'); 

但它只會顯示新的徽標example.com/testing而不是example.com/testing/test2。任何提示如何使它只是搜索網址是否包含單詞「測試」,而不僅僅是如果測試是基準名稱?

回答

0

嘗試如下

function new_headerimage(){ 
     if(strpos($_SERVER['REQUEST_URI'],'testing') !== false) { 

      echo '<div class="original-header"><a href="http://example.com/"><img src="http://example.com/wp-content/uploads/2016/04/logotest2.jpeg" alt="logo" /></a></div>'; 
     } else { 

      echo '<div class="testing-header"><a href="http://example.com/testing"><img src="http://example.com/wp-content/uploads/2016/04/logotest.jpeg" alt="logo image" /></a></div>'; 

    } 
} 
add_action('genesis_header', 'new_headerimage'); 
相關問題