php - How To Make Featured Image/Post Thumbnail to be the background image of a DIV? -
so have code:
<?php $background = wp_get_attachment_image_src( get_post_thumbnail_id( $page->id ), 'full' ); ?> <div class="imgholder" style="background-image: url('<?php echo $background[0]; ?>');">
the first line (php) , enable featured image/post thumbnail background image of specified div container.
the second line div container css style of background assigns featured image/post thumbnail.
to summarize, code works make featured image/post thumbnail (in its default size) background image.
the codes works charm, hands down person coded that!
my situation, want modify fit needs.
i have function below tasked crop , resize image.
add_theme_support('typeoneimage'); set_post_thumbnail_size( 726, 525, true ); add_image_size( 'typetwo', 726, 525, true );
my problem is, how can integrate 2 codes one.
what i'm trying achieve here make featured image/post thumbnail attachment 'typeoneimage' background of div?
why don't first code above? it's because first code generates default or original size of image. need smaller , cropped. i'm after smaller size believe affects site's speed.
hope help.
try
<?php $background = wp_get_attachment_image_src( get_post_thumbnail_id( $page->id ), 'typetwo' ); ?> <div class="imgholder" style="background-image: url('<?php echo $background[0]; ?>');">
i assume typetwo or 726 x 525is size want . if looking smaller size . either change function values add_image_size( 'typetwo',640,560, true ); or add new 1 called
add_image_size( 'postbg',640,560, true );
last don't forget use regenerate thumbnails plugin regenerate post thumbnails
Comments
Post a Comment