dongtu4559 2014-01-20 07:04
浏览 19
已采纳

来自外部URL的特色图片无法正常工作

I am trying to use external image as featured image in wordpress. All is done correctly but there is just one problem. The actual external image show only when there is any featured image set via the WP admin. I don't want to set any featured image but still want the featured image from that external URL which is set via a custom field.

I hope you guys got it. Here is the code of my content.php and the external featured image is triggered by get_post_meta($post->ID, "external_featured", true);

<article <?php post_class('single-entry clearfix'); ?>>  
<?php if( has_post_thumbnail() ) {  ?>   
    <div class="single-entry-thumbnail view view-first">
       <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?php echo get_post_meta($post->ID, "external_featured", true); aq_resize( wp_get_attachment_url( get_post_thumbnail_id(), 'full' ),  wpex_img( 'blog_entry_width' ), wpex_img( 'blog_entry_height' ), wpex_img( 'blog_entry_crop' ) ); ?>" alt="<?php echo the_title(); ?>" /></a>

        <div class="mask">
             <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
             <p>
                <?php
                    if( !empty($post->post_excerpt) ) {
                        the_excerpt();
                        } else {
                           echo wp_trim_words(get_the_content(), 20); }
                ?>
            </p>
            <a href="<?php the_permalink(); ?>" class="info">Download</a>
        </div>
    </div><!-- /single-entry-thumbnail -->
<?php } ?>
</article><!-- /single-entry -->

Thank you :)

  • 写回答

1条回答 默认 最新

  • douzhi1813 2014-01-20 13:16
    关注

    Try this:-

    <article <?php post_class('single-entry clearfix'); ?>>   
        <div class="single-entry-thumbnail view view-first">
        <?php $custom_featured_image_url = get_post_meta($post->ID, "external_featured", true); ?>
           <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?php echo $custom_featured_image_url; aq_resize( $custom_featured_image_url,  wpex_img( 'blog_entry_width' ), wpex_img( 'blog_entry_height' ), wpex_img( 'blog_entry_crop' ) ); ?>" alt="<?php echo the_title(); ?>" /></a>
    
            <div class="mask">
                 <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
                 <p>
                    <?php
                        if( !empty($post->post_excerpt) ) {
                            the_excerpt();
                            } else {
                               echo wp_trim_words(get_the_content(), 20); }
                    ?>
                </p>
                <a href="<?php the_permalink(); ?>" class="info">Download</a>
            </div>
        </div><!-- /single-entry-thumbnail -->
    </article><!-- /single-entry -->
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向