我使用Set featured Image
在WordPress的每篇博客文章的頂部顯示一個圖像。我使用的代碼很簡單,但編輯它改變了它的所有帖子後,當沒有工作允許每個博客帖子有不同的特色照片
<?php get_header(); ?>
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<div class="featured-image">
<div class="featured-image-wrap">
<!-- Post Thumbnail -->
<?php if (has_post_thumbnail()) : // Check if Thumbnail exists ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_post_thumbnail(); // Fullsize image for the single post ?>
</a>
<?php endif; ?>
<!-- /Post Thumbnail -->
</div>
</div>
<!-- Section -->
<section class="blog">
<!-- Article -->
<article class="blog-post" id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- Post Title -->
<h1>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</h1>
<!-- /Post Title -->
<!-- Post Details -->
<span class="date"><h2>Written By <?php the_author(); ?> on <?php the_time('F j, Y'); ?></h2></span>
<!-- /Post Details -->
<?php the_content(); // Dynamic Content ?>
<br class="clear">
<?php the_tags(__('Tags: ', 'html5blank'), ', ', '<br>'); // Separated by commas with a line break at the end ?>
<p><?php _e('Categorised in: ', 'html5blank'); the_category(', '); // Separated by commas ?></p>
<?php edit_post_link(); // Always handy to have Edit Post Links available ?>
</article>
<!-- /Article -->
<?php endwhile; ?>
<?php else: ?>
<!-- Article -->
<article>
<h1><?php _e('Sorry, nothing to display.', 'html5blank'); ?></h1>
</article>
<!-- /Article -->
<?php endif; ?>
</section>
<!-- /Section -->
<div class="finished">
<h2>Finished! Any Questions?</h2>
<p>If you have any questions please feel free to email me or <a href="http://twitter.com/joshua_hornby">Tweet me</a>. If you learnt anything in this lesson or found it useful please share with your friends.</p>
<a href="https://twitter.com/share" class="twitter-share-button" data-via="joshua_hornby" data-size="large">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</div>
<div class="blog-footer">
<aside class="footer-content">
<div class="dark-btn-footer-twitter"><a href="http://twitter.com/joshua_hornby" target="_blank">@joshua_hornby</a></div>
<div class="dark-btn-footer-twitter bottom"><a href="http://designer-school.com">More Posts</a></div>
</aside>
</div>
Alhough當過我改變形象。有沒有辦法讓每個帖子都有自己的特徵圖像?
當然你正在使用這個在你的single.php循環裏面。只是爲了向你確認。 – 2013-04-09 18:40:55
是的,這是在我的single.php – joshuahornby10 2013-04-09 18:41:35
裏面循環?因爲如果沒有,你應該使用get_the_post_thumbnail($ id,$ size,$ attr)而不是the_post_thumbnail() – 2013-04-09 18:42:12