php - Wordpress thumbnail from category as background div -



php - Wordpress thumbnail from category as background div -

i've got problem wordpress.

i want thumbnail of lastly post background of div.

code:

<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 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>

this works fine thumbnail of lastly post (all post). want thumbnail lastly post of category id 3.

how can prepare this?

thanks, bjorn

you calling query after have created thumbnail. query should wrap div.

try:

<?php $cat_id = 3; //the 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(); ?> <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] ); } ?>></div> <?php endwhile; endif; ?>

php wordpress background thumbnails

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -