wordpress网站的默认缩略图

时间:2016-09-18 10:27:10

标签: php wordpress thumbnails

我尝试修改自定义wp主题并添加相关的帖子块。我想为没有它的帖子添加默认缩略图。下面的代码工作正常,但我无法归档如何添加默认的img。

$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>';
        }
    }
} 

2 个答案:

答案 0 :(得分:0)

如果找不到帖子精选图片,为了打印默认缩略图,您必须打印图像文件夹中的默认图像。

library(ggplot2)
library(scales)
require(ggplot2)


start_btc=50
halvening_b=210000
time_prb=10
min_day=60*24
btcsupply=0
btcblockks=0
initial_date="2009-01-03"

start_time=0

period_ov=365*20

data_matrix_ts=matrix(nrow=period_ov,ncol=2)
colnames(data_matrix_ts) <- c("Date", "BTCSupply")

for (i in 1:period_ov){

  btcblocks=i*min_day/time_prb
  btcsupply=btcsupply+min_day/time_prb*start_btc/(2^(floor(btcblocks/halvening_b)))

  mat_date=as.Date(i,origin=initial_date)
  data_matrix_ts[i,1]=toString(mat_date)
  data_matrix_ts[i,2]=btcsupply
}

data_matrix_ts_df=as.data.frame(data_matrix_ts)

data_matrix_ts_df$Date <- as.Date( data_matrix_ts_df$Date, '%Y-%m-%d')
BSB_plot_1=ggplot(data = data_matrix_ts_df, aes( Date, BTCSupply, group=1 )) + geom_line()

以上代码的作用是什么?

检查帖子是否有缩略图,如果不是,则根据您的要求分配default-thumb-img.png(将其更改为您的图像名称)。

答案 1 :(得分:0)

我的解决方案只是硬编码绝对链接到默认缩略图

$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>';
                            }
                        }
                    }