来自外部URL的精选图片无法正常工作 [英] Featured Image from External URL not Working Properly

查看:68
本文介绍了来自外部URL的精选图片无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用外部图像作为wordpress中的特色图像。一切都正确完成,但是只有一个问题。实际的外部图像仅在通过WP管理员设置了任何特色图像时显示。我不想设置任何特色图片,但仍然希望通过自定义字段从该外部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.

我希望你们能理解。这是我content.php的代码,外部特色图片由 get_post_meta($ post-> ID, external_featured,true);

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 -->

谢谢:)

推荐答案

尝试以下操作:-

<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 -->

这篇关于来自外部URL的精选图片无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆