2012-04-13 9 views
1

私はカテゴリから最初の投稿を取得するための「奇妙な」クエリを作成しようとしている中で最初のポストから取り上げ画像をエコーと機能を備えた画像URLをエコーする - のimg htmlタグに包まれました。WordpressのWPのクエリは、検索およびカテゴリ

なぜこのようにしているのか聞かないでください。私は下の私の質問は理論的に動作するはずだと思う、私はそれがページを壊すように私のPHPの悪い構文だと思う - 誰でも私を修正するのを助けてくれる?

<?php 

    $featureThumb  = new WP_Query(array(

    'post_type'   => 'post', 
    'order'    => 'DESC', 
    'orderby'   => 'date', 
    'posts_per_page' => 1, 
    'cat'    => 4 

)); 

if ($featureThumb->has_post_thumbnail($post->ID)) { 

    $retina = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'homepage-thumb-retina'); 

    echo '<img src="' . $retina[0] . '" alt="' . the_title() . '" width="24" height="24" />' ; 

}; 

endwhile; 

unset($featureThumb); 

endif; wp_reset_query(); 

?> 

答えて

1

のように気にいら:

<?php 
$featureThumb = new WP_Query(array(
    'post_type'   => 'post', 
    'order'    => 'DESC', 
    'orderby'   => 'date', 
    'posts_per_page' => 1, 
    'cat'    => 4 
)); 

while ($featureThumb->have_posts()) : $featureThumb->the_post(); 
    if (has_post_thumbnail($post->ID)) { 
     $retina = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'homepage-thumb-retina'); 
     echo '<img src="' . $retina[0] . '" alt="' . the_title() . '" width="24" height="24" />' ; 
    }; 
endwhile; 

unset($featureThumb); 

wp_reset_query(); 
?> 
+0

どうもありがとう!どこが間違っているのか分かります。私がしばらく必要だったとは思っていませんでしたが、今は最初に投稿を取得するのが理にかなっています。 – Joshc

0

たぶん、あなたが行くここでは、この

 $postsQuery  = new WP_Query(array(

    'post_type'   => 'post', 
    'order'    => 'DESC', 
    'orderby'   => 'date', 
    'posts_per_page' => 1, 
    'cat'    => 4 

)); 

while ($postsQuery->have_posts()) 
{ 
     $postsQuery->the_post(); 
if(has_post_thumbnail($post->ID)) 
{ 

    $retina = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'homepage-thumb-retina'); 

    echo '<img src="' . $retina[0] . '" alt="' . the_title() . '" width="24" height="24" />' ; 

}; 
} 



unset($postsQuery); 

wp_reset_query(); 
+0

ちょっと時間を割いて男のおかげで、これもおそらく働いていただろう。乾杯! – Joshc

関連する問題