2011-11-24 124 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(); 
?> 
相关问题