$args = array( 'numberposts' => '3' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo '<a style="color:white;text-decoration:none;" href="'. get_permalink($recent["ID"]) .'">
<article class="post post_home" style="background-image: url('.
function(){
if( has_post_thumbnail() ) {
echo get_the_post_thumbnail_url( $recent["ID"], 'cover' );
} elseif ( has_category( 'positive-morning' ) ) {
echo get_bloginfo('template_directory') . '/img/BG/2-Morning.jpg';
} elseif ( has_category( 'positive-talks' ) ) {
echo get_bloginfo('template_directory') . '/img/BG/2-Talks.jpg'; }}
. ');
background-position : center; background-size :cover;">
<h2>'. $recent["post_title"] .'</h2></article>';
Hi all,
I'm having trouble to put an if statement because when I add the if statement supposed to declare if the post has no thumbnails, it should get the relative path to display the thumbnails defined for the category.
I've tried different ways to make it work but I can't find what's the problem. The only error I get is "Object of class Closure could not be converted to string"
Thanks for any help
Aucun commentaire:
Enregistrer un commentaire