Initially, I would guess there is an issue insaw the double and single quotes all jumbled up. This did fix some of what I saw, but I finally had time to test the code you put up.
First step, I used var_dump
on $recent_posts
to make sure I was getting the usable values.
Next, I echoed each variable as it was called, to make sure I knew what was being generated. I discovered that this line, as @james-barrett said, was not calling correct information:
echo '<div$post_thumbnail_id class="post_thumb"= style="background-image:url('.get_the_post_thumbnailget_post_thumbnail_id($post->ID);
So, I used @james-barrett's suggestion and changed it to:
$post_thumbnail_id $recent['ID'],= 'thumbnail').'get_post_thumbnail_id($recent["ID"])"></div>';;
The singleWhich then worked to get the correct ID.
After I was calling the correct information, the url()
portion was filling correctly, but the next problem was getting the correct size called.
I did some research and double quotes are conflictingdiscovered how the files were saved in the 'uploads' folder and then continued on to search for a way to access a function that would allow me to reach the one labled "thumbnail". The solution I have had issues likefound might not work with other sizes, or perhaps you could do more research after this, try usingbut I changed the $post_thumbnail_url
variable to this:
$post_thumbnail_url = wp_get_attachment_thumb_url( $post_thumbnail_id );
Which resulted in the 150x150 image being called.
After all was said and done, I converted your broken code above to this working code:
<?php
$args = array( 'numberposts' => '2' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
$post_thumbnail_id = get_post_thumbnail_id($recent["ID"]);
$post_thumbnail_url = wp_get_attachment_thumb_url( $post_thumbnail_id );
echo '<div class="post">';
echo '<div class="post_thumb" style="background-image:url('\''.get_the_post_thumbnail($post_thumbnail_url.'\')"></div>';
$recent["ID"], "thumbnail") echo '<div class="content"';
echo '<h2 class="post_title">';
echo '<a href="'.'get_permalink($recent["ID"])"><.'" title="'.$recent["post_title"].'" >'.$recent["post_title"].'</a>';
echo '</h2>';
echo '<p class="post_excerpt">'.$recent["post_excerpt"].'</p>';
echo '</div>'; //content
echo '</div>'; //.post
}
?>
If that doesn't workNote: I adjusted the url() to be url('') because some of my older browsers require the single quotes, then webut I suspect you can try more complex answersremove them.