我不是特别熟悉wordpress,但我一直致力于将我的布局写成主题,这样我就可以使用wordpress平台了。由于某些原因,我不能让the_post_thumbnail函数工作。我已经添加了
add_theme_support( 'post-thumbnails' );添加到我的functions.php文件中,是的,我设置了一个特色图像,并在循环中包含了the_post_thumbnail();。
我做错了什么?我甚至仔细检查了实际的函数,发现它在引用wp_get_attachment_image_src()函数时,wp_get_attachment_image()函数中的$image变量有问题。$image是空的,而我猜它不应该是空的。它得到的是post_thumbnail id,所以我知道它知道有一个图像集。它就是不会显示那个该死的东西。
我正在从头开始给自己写一个自定义主题,所以如果你好奇的话,functions.php只有add_theme_support( 'post-thumbnails‘)。
编辑:
下面是我的循环:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="home-entry clearfix" id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" rel="bookmark" >
<?php
if (has_post_thumbnail()) {
the_post_thumbnail();
} else {
echo '<img class="home-thumb trans-border" src="' . catch_first_image() . '" width="200px" height="150px" title="' . the_title() . '" />';
}
?>
</a>
<div class="home-post">
<div class="home-meta">Posted <?php the_time('M j, Y'); ?> - <?php the_category(' , ') ?> - <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></div>
<h2 class="post-title">
<a href="<?php the_permalink(); ?>" title="Permanent Link to <?php the_title_attribute(); ?>" rel="bookmark" class="title"><?php the_title(); ?></a>
<a class="read" href="<?php the_permalink(); ?>" title="Read More">Read More</a>
</h2>
<div class="home-excerpt">
<?php the_excerpt(); ?>
</div>
</div>
</div>
<?php endwhile; ?>
<?php echo paginate_links() ?>
<?php else : ?>
<h2>Nothing Found</h2>
<?php endif; ?> 续:
所以我去找了一个有特色图片支持的主题,完全复制了循环的那部分,但仍然一无所获:
<?php if(has_post_thumbnail()) {
echo '<span class="thumbnail"><a href="'; the_permalink(); echo'">';the_post_thumbnail(array(100,100)); echo '</a></span>';
} else {
$image = evlget_first_image();
if ($image):
echo '<span class="thumbnail"><a href="'; the_permalink(); echo'"><img src="'.$image.'" alt="';the_title();echo'" /></a></span>';
endif;
} ?>那么它到底是什么呢?我很困惑..。
发布于 2012-06-08 06:27:56
此函数将回显自身。
解决方法:去除函数前面的回声。
检查this
发布于 2013-06-07 09:48:59
您的图像是否存储在本地服务器/本地计算机上?否则,the_post_thumbnail()将无法工作,因为它不能基于URL检索图像。
https://stackoverflow.com/questions/10940629
复制相似问题