1

カテゴリから最初の投稿を取得し、img html タグでラップされた注目の画像 URL をエコーする「奇妙な」クエリを作成しようとしています。

なぜ私がこのようにしているのか聞かないでください。以下のクエリは理論的には機能するはずだと思いますが、ページが壊れるため、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();

?>
4

2 に答える 2

2

どうぞ:

<?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();
?>
于 2012-04-13T10:06:18.543 に答える
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();
于 2012-04-13T10:00:04.247 に答える