2014-03-24 38 views
0

我創建了一個模板category-beers.php,它應該顯示來自單個類別的所有帖子。所有帖子都應顯示在表格中。一切正常,但這個代碼只顯示3個最近的帖子。我應該編輯什麼來顯示此類別的所有帖子?爲什麼此代碼只顯示3個條目? WP

<table class="drinked-beers"> 
<tr> 
<th>Beer</th> 
<th>Consumer</th> 
<th>I drinked this beer on </th> 
<th>Style</th> 
<th>Note</th> 

</tr> 
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
<tr> 
<td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td> 
<td><?php the_author(); ?></td> 
<td><?php the_date(''); ?> </td> 
<td><?php the_tags(''); ?> </td> 
<td><?php echo get_post_meta($post->ID, 'my-note', true); ?></td> 
</tr> 
<?php endwhile; endif; ?> 
</table> 
+0

您的帖子數設置爲3嗎?進入'Settings-> Reading'來檢查 –

+0

是的。但我需要在我的主頁上顯示3個帖子。我可以在上面的代碼中設置以顯示所有帖子嗎? –

+0

這是唯一的代碼頁面?有沒有更多? – Stewartside

回答

0

我沒有測試過這個,但我認爲它會達到你要找的。

<?php 
$categories = get_the_category(); 
$category_id = $categories[0]->cat_ID; 
$args = array('category' => $category_id, 'post_type' => 'post' , 'numberposts'=>-1); 
$posts = get_posts($args);  
foreach ($posts as $post){ 
    setup_postdata($post);?> 

    <tr> 
     <td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td> 
     <td><?php the_author(); ?></td> 
     <td><?php the_date(''); ?> </td> 
     <td><?php the_tags(''); ?> </td> 
     <td><?php echo get_post_meta($post->ID, 'my-note', true); ?></td> 
    </tr> 
<?php 
} 
相關問題