2016-09-18 3 views
0

Ich versuche, meine benutzerdefinierte WP-Thema zu ändern und verwandte Post-Block hinzufügen. Ich möchte ein Standard-Thumbnail für Beiträge hinzufügen, die es nicht haben. Unten Code funktioniert gut, aber ich kann nicht archivieren, wie Standard-IMG hinzufügen.Standard Thumbnail für Wordpress-Website

$args = array('numberposts' => '4','post__not_in' => array($post->ID)); 
$recent_posts = wp_get_recent_posts($args); 
foreach($recent_posts as $recent) { 
    if($recent['post_status']=="publish") { 
     if (has_post_thumbnail($recent["ID"])) { 
     echo '<div><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . get_the_post_thumbnail($recent["ID"], 'thumbnail'). $recent["post_title"].'</a></div> '; 
     } else { 
      echo '<div><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . $recent["post_title"].'</a></div>'; 
     } 
    } 
} 

Antwort

0

Um das Standard-Thumbnail zu drucken, wenn das Posts-Featured-Bild nicht gefunden wird, müssen Sie das Standardbild, das Sie in Ihrem Bilder-Ordner haben, ausdrucken.

<?php if (has_post_thumbnail()) { 
the_post_thumbnail(); 
} else { ?> 
<img src="<?php bloginfo('template_directory'); ?>/images/default-thumb-img.png" 
alt="<?php the_title(); ?>" /> 
<?php } ?> 

Was macht der obige Code?

Es prüft, ob die Post Thumbnails hat, wenn nicht die Standard-thumb-img.png (Ändern Sie es zu Ihrem Bildnamen) nach Ihren Anforderungen.

0

meine Lösung ist hart codiert nur absoluten Link Thumbnail auf Standard

$args = array('numberposts' => '4','post__not_in' => array($post->ID)); 
        $recent_posts = wp_get_recent_posts($args); 
        foreach($recent_posts as $recent){ 
         if($recent['post_status']=="publish") { 
          if (has_post_thumbnail($recent["ID"])) { 
           echo '<div class="col-md-3 col-lg-3"><div class="recent-post-holder"><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . get_the_post_thumbnail($recent["ID"], 'thumbnail'). $recent["post_title"].'</a></div></div> '; 
          } else { 
           echo '<div class="col-md-3 col-lg-3"><div class="recent-post-holder"><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . "<img src='/*add link here*/'>". $recent["post_title"].'</a></div></div>'; 
          } 
         } 
        }