【问题标题】:Replace theme header image with featured image in wordpress用wordpress中的特色图片替换主题标题图片
【发布时间】:2014-11-02 17:46:23
【问题描述】:

我在 Wordpress 上使用 Casper 主题。它在整个网站上显示标题图像,但是我希望它在查看帖子时显示特色图像。

我在 header.php 中找到了下面的代码

<header id="masthead" role="banner" class="site-head site-header" <?php if(get_header_image() ) : ?>style="background-image: url(<?php header_image(); ?>);"<?php endif ?>>

任何帮助将不胜感激。

谢谢

【问题讨论】:

    标签: php wordpress image replace themes


    【解决方案1】:

    你可以试试这样的

    <?php
        if ( is_singular() && has_post_thumbnail( $post->ID ) &&  ($image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) && $image[1] >= HEADER_IMAGE_WIDTH ) :
           echo get_the_post_thumbnail( $post->ID );
       elseif ( get_header_image() ) : ?>
           <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
    <?php endif; ?>
    

    【讨论】:

    • 感谢拉姆的建议。我设法通过安装一个名为“Custom Header Extended”的插件来修复它。如果我以后想更改主题,我认为您的解决方案会更好。
    猜你喜欢
    • 2014-09-28
    • 2012-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-07
    • 2012-11-30
    • 2019-12-11
    • 1970-01-01
    相关资源
    最近更新 更多