the_post_thumbnail无效

时间:2012-06-07 22:16:20

标签: wordpress wordpress-theming

我对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;
           } ?>

那到底是什么意思呢?我很困惑......

2 个答案:

答案 0 :(得分:0)

此功能将自行回响。

如何解决:删除函数前面的回显。

检查this

答案 1 :(得分:0)

您的图片是否存储在您的服务器/本地计算机上? 如果没有,the_post_thumbnail()将无法工作,因为它无法根据URL检索图像。