【发布时间】:2016-01-13 23:15:44
【问题描述】:
我希望有人能帮助我解决我遇到的问题...
我目前正在构建一个 Wordpress 网站,并且正在整理帖子部分。一切似乎都很好,当在帖子上使用特色图片时,它可以很好地显示在此处的缩略图中:http://5.10.105.45/~learningforsusta/index.php/education-for-sustainable-development/,然后很好地显示在单个帖子中:http://5.10.105.45/~learningforsusta/index.php/efsc-post/example-post-1/
但是,在没有指定特色图片的帖子上,它似乎显示的是默认图片...
我的问题是,我怎样才能摆脱默认图像,如果没有特色图像,我希望它不显示任何东西......
这是我用来完成所有操作的代码:
<div class="container">
<div class="row">
<div class="col-md-9">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="page-header">
<?php
$thumbnail_id = get_post_thumbnail_id();
$thumbnail_url = wp_get_attachment_image_src( $thumbnail_id, 'thumbnail-size', true );
$thumbnail_meta = get_post_meta( $thumbnail_id, '_wp_attachment_image_alt', true);
?>
<p class="featured-image"><img src="<?php echo $thumbnail_url[0]; ?>" alt="<?php echo $thumbnail_meta; ?>"></p>
<p><em>
By <?php the_author(); ?>
on <?php echo the_time('l, F jS, Y');?>
in <?php the_category( ', ' ); ?>.
<a href="<?php comments_link(); ?>"><?php comments_number(); ?></a>
</em></p>
</div>
<?php the_content(); ?>
<hr>
<?php comments_template(); ?>
<?php endwhile; else: ?>
<div class="page-header">
<h1>Oh no!</h1>
</div>
<p>No content is appearing for this page!</p>
<?php endif; ?>
</div>
<?php get_sidebar( 'blog' ); ?>
</div>
这里是与缩略图相关的 functions.php 文件中的代码...
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size(150, 120, true);
我确定我遗漏了一些简单的东西,但我尝试过改变一些东西,但我就是想不通!
任何帮助将不胜感激...
谢谢,
肖恩
【问题讨论】:
-
有趣...您共享的代码中没有任何内容表明存在默认图像。您是否尝试过在主题的源代码中搜索图像名称?您可能在某处缺少负责此默认输出的缩略图过滤器。
-
老实说,这是我的第一次经历!这就是为什么它没有意义......下面的人似乎有答案 - 我只是错过了 if 语句。这就是回复:)