0

私は自分のワードプレスにflexsliderをインストールしてうまく動作させています.ページに添付されたすべての画像を取得して表示します.すべての画像をそのファイルにリンクさせることは可能ですか?

私が使用しているコードはこれです

<ul class="slides">

    <php foreach ( $attachments as $attachment ) {  ?>

        <li><?php echo wp_get_attachment_image( $attachment->ID, 'cw-post' ); ?>
        </li>

    <?php } ?>

</ul>
4

1 に答える 1

0

これでうまくいくと思います。

// Get ID of the attached file
$thumbnail_id = get_post_thumbnail_id(get_the_ID());

// Get attached file. Define what size at the end. DEfault is the thumbnail.
$image_src_arr = wp_get_attachment_image_src($thumbnail_id,'medium');

// Return image source
$image_source = $image_src_arr[0];

myeslf 用に次の関数を作成しました。

/**
 * This function will return source url for attached image-
 * The get_the_ID is a global WP command that will retrieve current post / page ID
 * Using the post ID it will return the attachment ID needed in order to call
 * wp_get_Attachment_image_src.
 */
function get_related_image($size){
    $image_src_arr = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()),$size);

    if(sizeof($image_src_arr) > 0) {
        return $image_src_arr[0];
    } else {
        return false;
    }

}
于 2013-03-19T08:59:03.153 に答える