【问题标题】:Wordpress: post thumbnails/post image attachmentWordpress:发布缩略图/发布图片附件
【发布时间】:2012-07-14 05:11:42
【问题描述】:

我想在存档页面中的帖子旁边显示缩略图,但是只有在帖子有特色图片时才会显示缩略图。

是否可以将帖子的附加图像制作为缩略图并显示在存档页面中?

目前,如果设置为特色,我正在使用以下代码显示缩略图。

<?php if ( has_post_thumbnail()) : ?>
   <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
   <?php the_post_thumbnail(thumbnail, array('class' => 'alignleft')); ?>
   </a>
<?php endif; ?>

这里是网站http://n1bar.com/category/blog 如您所见,第一个帖子有一个附加图片,但在存档页面中没有显示为缩略图。

感谢任何帮助

【问题讨论】:

    标签: thumbnails


    【解决方案1】:

    以下代码可以为您提供帖子中的所有图片附件。 把它放在大的while循环中。 如果您只想显示 1 张图片,您可以修改下面的代码,因为如果有超过 1 张图片附件,我不确定您要显示哪张图片。

        <div class="allthumbs cf">
        <?php
    
            $args = array(
                'post_type' => 'attachment',
                'numberposts' => -1,
                'post_status' => null,
                'post_parent' => $post->ID,
                'order' => 'ASC',
    
            );
    
            $attachments = get_posts( $args );
            if ( $attachments ) {
                foreach ( $attachments as $attachment ) {
                    $full_img_url = wp_get_attachment_image_src( $attachment->ID, 'full' );
                    echo '<div class="imageWrapper zoom-able"><a href="' . $full_img_url[0] .'">' 
                        .wp_get_attachment_image( $attachment->ID, 'medium' ) . "</a></div>";
                }
            }       
        ?>
        </div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-29
      • 2011-09-15
      • 1970-01-01
      • 2018-07-04
      • 1970-01-01
      • 2018-01-18
      • 1970-01-01
      相关资源
      最近更新 更多