2017-06-17 46 views
0

我想改變只顯示在我的存檔頁面上的帖子, 請讓我知道如何做到這一點,謝謝。如何在歸檔頁面上顯示自定義的帖子數量?

這是從我的archive.php

<div id="content-a"> 

<?php if (have_posts()) : ?> 
<?php while (have_posts()) : the_post(); ?> 

<div class="post"> 
<div class="imgdiv"><a href="<?php the_permalink() ?>"><img src="<?php echo catch_that_image() ?>" width="250"></a></div> 
<div class="p-heading"><h1><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1></div> 
<div class="p-content"><?php the_excerpt(); ?></div> 
<div class="p-info"><?php the_time('j.m.Y') ?> | <?php the_category(', '); ?> | <img src="http://www.virmodrosti.com/wp-content/uploads/comments.png" alt="Komentarji" width="26" height="12"><?php $totalcomments = get_comments_number(); echo $totalcomments; ?></div> 
</div> 

<?php endwhile; ?> 

的代碼,我想有不同數量的存檔頁面職位。謝謝。

回答

3

將此代碼添加到您的functions.php中,並將帖子的數量從100改爲您希望顯示的數量。

function wpsites_query($query) { 
if ($query->is_archive() && $query->is_main_query() && !is_admin()) { 
     $query->set('posts_per_page', 100); 
    } 
} 
add_action('pre_get_posts', 'wpsites_query'); 

試試這個

function SearchFilter($query) { 
    if ($query->is_search) { 
     $query->set('post_type', 'archive'); 
     $query->set('posts_per_page', 100); 
    } 
    return $query; 
} 
add_filter('pre_get_posts','SearchFilter'); 
+0

謝謝。如果您也想將此規則應用於搜索結果,那麼您是否在is_archive之後添加了is_search? – Techuser

+0

檢查我已更新答案,但您應該在最後一次更改前嘗試。 –

+0

謝謝,它工作正常。 – Techuser

相關問題