Wordpress wp查询检索并回显类别中第一篇文章的特色图像
我试图创建一个“奇怪”的查询,从一个类别中检索第一篇文章,并回显用img html标记包装的特色图片URL 别问我为什么要这样做。我认为我下面的查询在理论上应该是可行的,我认为它在我的php中是糟糕的语法,因为它会破坏页面-有人能帮我修复吗Wordpress wp查询检索并回显类别中第一篇文章的特色图像,wordpress,Wordpress,我试图创建一个“奇怪”的查询,从一个类别中检索第一篇文章,并回显用img html标记包装的特色图片URL 别问我为什么要这样做。我认为我下面的查询在理论上应该是可行的,我认为它在我的php中是糟糕的语法,因为它会破坏页面-有人能帮我修复吗 <?php $featureThumb = new WP_Query(array( 'post_type' => 'post', 'order' => 'DES
<?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();
?>
可能是这样的事情
$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();
$postsQuery=新的WP\u查询(数组)(
“post_type”=>“post”,
“订单”=>“描述”,
'orderby'=>'date',
“每页帖子数”=>1,
“猫”=>4
));
而($postsQuery->have_posts())
{
$postsQuery->the_post();
如果(有帖子缩略图($post->ID))
{
$retina=wp\u get\u attachment\u image\u src(get\u post\u缩略图\u id($post->id),'homepage thumb retina');
回声';
};
}
未设置($postsQuery);
wp_reset_query();
给你:
<?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();
?>
非常感谢你,伙计!!!你能看出我哪里做错了。我不认为我需要时间,但现在有必要先检索帖子。嘿,伙计,谢谢你花时间,这可能也会奏效。干杯