2011-11-24 114 views
0

我在Wordpress中創建頁面,顯示與頁面標題相同標籤的所有帖子(例如,名爲'dog'的頁面的所有'狗'帖子。目標是能夠快速創建分類頁面。如何讓圖像在Wordpress模板中顯示循環?

我有波紋管成功的代碼顯示標題和後期的文字,但我想也顯示每個職位的圖像(如果該帖子有任何圖像)。2個問題...

- 如何每個帖子用wordpress顯示一個圖像?

- 如何在循環中實現上面的文字?

<?php 

/** 
* Template Name: Category Page Template 
* Description: A Page Template for Categories 
*/ 

get_header(); ?> 

     <div id="primary"> 
      <div id="content" role="main"> 


       <?php $catname = wp_title('', false); ?> 
<?php query_posts("category_name=$catname&showposts=3"); ?> 
<?php $posts = get_posts("category_name=$catname&numberposts=3&offset=0"); 
foreach ($posts as $post) : include(loop.php);?> 
<?php the_title(); ?> 
<?php the_excerpt(); ?> 
<?php endforeach; ?> 


      </div><!-- #content --> 
     </div><!-- #primary --> 

<?php get_footer(); ?> 

回答

0

添加

add_theme_support('post_thumbnails'); 
add_image_size('homepage-thumbnail',300, 200, true); 

你的functions.php,你可能也想在同一時間設置的圖像大小考慮set_post_thumbail_size()和add_image_size()來做到這一點

,並在循環添加類似

if (has_post_thumbnail()){ 
    the_post_thumbnail('homepage-thumbnail'); 
} 
0

1以獲取後的圖像是指this,請致電:

在一個循環
wp_get_attachment_image($attachment_id, $size, $icon, $attr) 

2.to將文字,這樣做:

<?php 
query_posts("category_name=$catname&posts_per_page=3"); 
while (have_posts()) : the_post(); 
    the_title(); 
    the_excerpt(); 
endwhile; 
wp_reset_query(); 
?> 
相關問題