【问题标题】:Wordpress PHP - How to show header on every page?Wordpress PHP - 如何在每个页面上显示标题?
【发布时间】:2015-11-18 03:23:58
【问题描述】:

如果有人可以提供帮助,将不胜感激。我在一个 Wordpress 网站上工作,我在主页上有一个标题图片。它只显示在主页上,但我需要它显示在每个页面上。我在 header.php 文件中发现了这段代码,我认为需要更改,但我对 php 不是很熟悉。

这是header.php文件中标题图片的代码:

<?php if ( is_home() || is_front_page() ) { ?>
  <?php if ( get_header_image() != '' && $papercuts_options_db['papercuts_display_header_image'] != 'Everywhere except Homepage' ) { ?>
    <div class="header-image-wrapper"><div class="header-image"><img src="<?php header_image(); ?>" alt="<?php bloginfo( 'name' ); ?>" /></div></div>
  <?php 
    }  
  } else { ?>
  <?php if ( get_header_image() != '' && $papercuts_options_db['papercuts_display_header_image'] != 'Only on Homepage' ) { ?>
      <div class="header-image-wrapper"><div class="header-image"><img src="<?php header_image(); ?>" alt="<?php bloginfo( 'name' ); ?>" /></div></div>
  <?php } 
  } ?> 

【问题讨论】:

  • 找到所有页面使用的主模板php,调用顶部的header.php。

标签: php html wordpress


【解决方案1】:

将代码替换为:

<?php 
if ( get_header_image() != '' ) { 
?>
    <div class="header-image-wrapper"><div class="header-image"><img src="<?php header_image(); ?>" alt="<?php bloginfo( 'name' ); ?>" /></div></div>
<?php 
}
?>

最好保留原始代码但注释掉 - 使用:

<?php 
/*
if ( is_home() || is_front_page() ) { ?>
  <?php if ( get_header_image() != '' && $papercuts_options_db['papercuts_display_header_image'] != 'Everywhere except Homepage' ) { ?>
    <div class="header-image-wrapper"><div class="header-image"><img src="<?php header_image(); ?>" alt="<?php bloginfo( 'name' ); ?>" /></div></div>
  <?php 
    }  
  } else { ?>
  <?php if ( get_header_image() != '' && $papercuts_options_db['papercuts_display_header_image'] != 'Only on Homepage' ) { ?>
      <div class="header-image-wrapper"><div class="header-image"><img src="<?php header_image(); ?>" alt="<?php bloginfo( 'name' ); ?>" /></div></div>
      <?php } 

  } 
*/ ?> 

供参考

【讨论】:

  • 这行得通,谢谢!你知道我怎样才能让标题不会偶然出现在特定页面上吗?事实证明,我需要它显示在某些页面上而不是其他页面上。
  • 您可以获取页面信息并相应显示 - get_the_title();例如,将为您提供标题,因此您可以添加: $postID = get_the_ID(); if ( get_header_image() != '' && $postID != 5) { 如果您不想显示的页面的页面 id 是 5,您可以重复 && $postID != 位添加其他人
【解决方案2】:
 <?php if ( get_header_image() !='') { ?>
    <div class="header-image-wrapper"><div class="header-image"><img src="<?php header_image(); ?>" alt="<?php bloginfo( 'name' ); ?>" /></div></div>
  <?php 
     } ?>

用上面的代码替换。我认为它会起作用。

【讨论】:

    猜你喜欢
    • 2019-08-13
    • 1970-01-01
    • 1970-01-01
    • 2011-07-22
    • 1970-01-01
    • 2016-01-06
    • 2013-01-14
    • 2011-08-09
    • 1970-01-01
    相关资源
    最近更新 更多