【发布时间】:2014-06-20 05:54:41
【问题描述】:
我在使用 Wordpress 时遇到了问题。
我希望我上一篇文章的缩略图作为我的 div 的背景。
代码:
<div<?php
if ( $thumbnail_id = get_post_thumbnail_id() ) {
if ( $image_src = wp_get_attachment_image_src( $thumbnail_id, 'normal-bg' ) )
printf( ' style="background-image: url(%s);"id="photopost"', $image_src[0] );
}
?><?php $cat_id = 3; //the certain category ID
$latest_cat_post = new WP_Query( array('posts_per_page' => 1, 'category__in' => array($cat_id)));
if( $latest_cat_post->have_posts() ) : while( $latest_cat_post->have_posts() ) : $latest_cat_post->the_post(); ?><?php endwhile; endif; ?>></div>
这适用于我上一篇文章(所有文章)的缩略图。 但我想要类别 ID 3 的最后一篇文章的缩略图。
我该如何解决这个问题?
谢谢, 比约恩
【问题讨论】:
标签: php wordpress background thumbnails