wordpress在缩略图大小的单个cpt上显示附件

时间:2014-12-23 03:43:53

标签: wordpress thumbnails

我有单个cpt显示atachment的片段,但我现在不知道如何在代码中获取atachment图像大小,让我们说..我想为图像添加缩略图大小,但我不知道如何...

这是我使用的代码

<?php $args = array(
'numberposts' => -1, // Using -1 loads all posts
'orderby' => 'menu_order', // This ensures images are in the order set in the page media manager
'order'=> 'ASC',
'post_mime_type' => 'image', // Make sure it doesn't pull other resources, like videos
'post_parent' => $post->ID, // Important part - ensures the associated images are loaded
'post_status' => null,
'post_type' => 'attachment',
);

$images = get_children( $args ); if($images){ ?>
<div id="projectGallery">
<?php foreach($images as $image){ ?>
<img src="<?php echo $image->guid; ?>" alt="<?php echo $image->post_title; ?>" title="<?php echo $image->post_title; ?>" />
<?php} ?>
</div>
<?php } ?>

请帮助.. thx

2 个答案:

答案 0 :(得分:1)

请遵循以下代码。它会对你有所帮助。

<?php
    $size = thumbnail, medium, large or full
    $args = array(
        'numberposts' => -1,
        'orderby' => 'menu_order',
        'order'=> 'ASC',
        'post_mime_type' => 'image',
        'post_parent' => $post->ID,
        'post_status' => null,
        'post_type' => 'attachment',
    );
    $images = get_children( $args );
    if($images){
?>
    <div id="projectGallery">
<?php
        foreach($images as $image){
            wp_get_attachment_image($image->ID, 'thumbnail'); //you can give thumbnail, medium, large or full according to your choice
<?php } ?>
    </div>
<?php } ?>

答案 1 :(得分:-1)

您可以使用

wp_get_attachment_thumb_url( $attachment_id ); 

如下:

<img src="<?php echo wp_get_attachment_thumb_url( $image->ID ); ?>" alt="<?php echo $image->post_title; ?>" title="<?php echo $image->post_title; ?>" />