for reference http://vvcap.net/db/Bs03ucQSrylV5LBiWduY.htp here's a thumbnail of featured image of a post http://vvcap.net/db/_45qWkuQwluTrYF51tFn.htp here's a square i want to set the background-image of. The small square is made from a post loop (shown below). Inside the loop is a a check to see if the post as a "featured image attracted"
CSS: currently this is the only css that styles the div bg. (this should be replaced)
section > div { background:#00c8e8;}
Compiled source HTML the second section posts a featured image(ontop of div) as example. First section has no featured image.
<section class="resource">
<div>
<a href="http://localhost/dov1/?custom_type=logo-design" rel="bookmark" title=" Logo Design">Logo Design</a>
</div>
</section>
<section class="resource">
<div>
<a href="http://localhost/dov1/?custom_type=test" rel="bookmark" title=" Magazine Spread">Magazine Spread</a>
<img width="125" height="125" src="http://localhost/dov1/wp-content/uploads/2012/03/project2_web-125x125.jpg" class="attachment-post-thumbnail wp-post-image" alt="project2_web" title="project2_web" />
</div>
</section>
HTML/PHP
<?php
$args = array(
'post_type' => 'custom_type',
'posts_per_page' => '-1'
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<section class="resource">
<div>
<a href="<?php the_permalink() ?>" rel="bookmark" title=" <?php the_title_attribute(); ?>">
<?php the_title(); ?>
<?php
// check if the post has a Post Thumbnail assigned to it.
if ( has_post_thumbnail() )
{
//run jQuery here (prob replace the_post_thumbnail();)
the_post_thumbnail();
}
?>
</a> </div>
</section>
<?php endwhile; ?>
I'm not very strong with jQuery or php. Luckily, the logic to this process makes sense.
- Loop the posts (check)
- Test to see if posts have featured image (check)
- Execute jQuery to replace the background images with the_post_thumbnail();
- Profit!
Where we run into another caveat is how do we distinguish and assign the distinguished the proper background image? I only have 1 form fitting css style. It would make sense if it treated the process per entry. Unfortunately, wouldn't it rewrite over each entry? I know this is a big question stack but please I'll love you forever for the help!
Matthew
UPDATED HTML SOURCE
<section class="resource">
<div>
<a href="http://localhost/dov1/?custom_type=test" rel="bookmark" title=" Magazine Spread">Magazine Spread</a>
<img width="125" height="125" src="http://localhost/dov1/wp-content/uploads/2012/03/project2_web-125x125.jpg" class="attachment-post-thumbnail wp-post-image" alt="project2_web" title="project2_web" /> </div>
</section>
img
element that's in thediv
? And the image should become the background-image of thediv
itself? Should theimg
be removed subsequently? – David says reinstate Monica