[英]How to make header show only on home page? Wordpress
這是我正在使用wordpress編輯的網站:
www.thestudentbubble.com
如您所見,有3個行標頭說明了網站的內容。 如何使它僅顯示在主頁上?
我找到了Header.php文件,當前代碼如下所示:
<?php if ( get_header_image() ) : ?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<img src="<?php header_image(); ?>" class="header-image" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" /></a>
<?php endif; ?>
嘗試這個:
<?php
if ( is_home() ) {
// This is a homepage
} else {
// This is not a homepage
}
?>
WordPress is_home()函數。 您也可以使用is_frontpage()
<?php
if ( is_front_page() ) {
// This is a homepage
} else {
// This is not a homepage
}
?>
關於這些之間的區別的更多信息:
if ( is_front_page() && is_home() ) {
// Default homepage
} elseif ( is_front_page() ) {
// static homepage
} elseif ( is_home() ) {
// blog page
} else {
//everyting else
}
使用is_home函數檢查您是否在主頁中。
<?php if (is_home()): ?>
<!-- ... -->
<?php endif; ?>
如果出現這種情況,請輸入您的代碼-
if( is_front_page())
{
///put code here to show only on home page header
}
一個更整潔的解決方案是將現有條件(如果失敗,可能會很好地回退)更改為:
<?php if ( get_header_image() && is_home() ) : ?>
我希望我的Wordpress模板的標題圖像僅顯示在主頁上, 而不顯示在其他任何頁面上。
我必須編輯模板的header.php文件並添加:
<!-- Custom Header - Start -->
<?php if ( is_front_page() ) : ?>
$header_image = get_header_image();
[...]
<?php endif; // end check for featured image or standard header ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.