【发布时间】:2016-07-30 04:54:33
【问题描述】:
我正在使用 wordpress,我想仅在页面(不是帖子)上将图像添加到页眉。
你有这个功能吗?
谢谢
【问题讨论】:
我正在使用 wordpress,我想仅在页面(不是帖子)上将图像添加到页眉。
你有这个功能吗?
谢谢
【问题讨论】:
主题是您自己创建的吗?如果是,您可以在要显示图像的地方使用此功能:
<?php if(is_page()){
// The image
} ?>
如果没有,您可以创建一个子主题。如果您在主题文件夹中找到page.php,请将此文件复制到您的子主题文件夹中。如果不存在,请搜索 singular.php,如果不存在则搜索 index.php。将其中一个复制到您的子主题文件夹中,并使用上面的代码if(is_page()){ 将图像放在那里。
【讨论】:
在你的主题->header.php中,寻找这段代码。它有 4 行(大约)。
<?php $header_image = get_header_image();
( There are 2 lines in this area, just don't touch them )
<?php endif; ?>
找到后,像这样将我们的代码添加到顶行和底行
<?php if( is_page() ) : ?>
<?php $header_image = get_header_image();
( There are 2 lines in this area, just don't touch them )
<?php endif; ?>
<?php endif; ?>
请记住,您正在实时编辑一个 php 文件,因此您必须非常小心,而且不用说您应该已经有备份,并且 FTP 登录以防万一出现问题。
// When any single Page is being displayed.
<?php if( is_page() ) : ?>
<?php $header_image = get_header_image();
if ( ! empty( $header_image ) ) : ?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>"><img src="<?php echo esc_url( $header_image ); ?>" class="header-image" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" /></a>
<?php endif; ?>
<?php endif; ?><br>
【讨论】: