2011-12-06 10 views
0

画像を含むすべてのアタッチメントを引っ張るのが本当に難しいです...事は、コンテンツがどのように表示されるかを制御できる必要があります...Wordpress: - おすすめ画像を含むすべての添付画像を引っ張る

<a href="(Path-to-full-image)" rel="customrel" class="aclasstodeine"> 
<img src="thethumbnailsize(defined in functions.php)" alt="" 
class="aclasstodefine" /> 
</a> 

は本当に誰かがあなたのクエリを実行するために必要なすべての添付ファイルの画像を取得するには

答えて

1

を助けることができると思います。

$args = array(
    'post_type'  => 'attachment', 
    'post_parent' => $post->ID, 
    'post_status' => 'inherit', 
    'numberposts' => -1 
); 

$images = get_posts($args); 

これはあなたのイメージを得るためにそれらの上にforeachループを行い、その後$画像変数にポストに接続されているすべての画像をロードします:

<?php foreach ($images as $i) : ?> 
    <a href="<?php wp_get_attachment_image_src($i->ID, 'full'); ?>" rel="customrel" class="aclasstodeine"> 
    <img src="<?php wp_get_attachment_image_src($i->ID, 'thumbnail'); ?>" alt="" class="aclasstodefine" /> 
    </a> 
<?php endforeach; ?> 

あなたがここにwp_get_attachment_image_src上に読むことができます:http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src

0

これは次のようになります。

$args = array(
    'post_type'  => 'attachment', 
    'post_parent' => $post->ID, 
    'post_status' => 'inherit', 
    'numberposts' => 1//-1 
); 
$images = get_posts($args); 

foreach ($images as $i) : 
    $poza_thumb = wp_get_attachment_image_src($i->ID, 'thumbnail'); 
    //$poza_fullsize = wp_get_attachment_image_src($i->ID, 'full'); 
    //print_r($poza_thumb);//you will see that $poza_thumb is an array containing url, width, height 
    ?> 
    <img src="<?php echo $poza_thumb[0];?>" width="<?php echo $poza_thumb[1];?>" height="<?php echo $poza_thumb[2];?>" rel="customrel" class="aclasstodeine"/> 

<?php 
endforeach; 
関連する問題