【问题标题】:Featured Image from External URL not Working Properly来自外部 URL 的特色图片无法正常工作
【发布时间】:2014-01-20 07:04:47
【问题描述】:

我正在尝试使用外部图片作为 wordpress 中的特色图片。一切都正确完成,但只有一个问题。仅当通过 WP 管理员设置了任何特色图像时,才会显示实际的外部图像。我不想设置任何特色图片,但仍希望通过自定义字段设置的外部 URL 中的特色图片。

我希望你们明白了。这是我的 content.php 的代码,外部特色图片由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 -->

谢谢你:)

【问题讨论】:

    标签: php wordpress custom-fields


    【解决方案1】:

    试试这个:-

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

    【讨论】:

    • 对不起..我粘贴错了..现在完美了:)再次感谢你:)
    • 是的,Stack Overflow Rocks!
    猜你喜欢
    • 2014-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-04
    • 1970-01-01
    • 2017-01-05
    • 1970-01-01
    • 2020-05-19
    相关资源
    最近更新 更多