2012-04-14 19 views

回答

1

到functions.php

function main_query_mods($query) { 
    if(!$query->is_main_query()) { 
     return; 
    } 
    // show 15 posts per page if category has id 7 
    // check http://codex.wordpress.org/Conditional_Tags#A_Category_Page 
    if (is_category('7')) { 
     $query->set('posts_per_page',15); 
    } 
} 
add_action('pre_get_posts', 'main_query_mods'); 
0

你應該使用這樣的:

<?php $the_query = new WP_Query ('cat=7&posts_per_page=15'); ?> 
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?> 
    <div><?the_title(); //display post title?></div> 
    <div><?the_content(); //display post content?></div> 
<?php endwhile; ?> 

cat是類別ID
post_per_page是極限,如果帖子

添加&orderby=rand到查詢將是隨機選擇的職位。

你可以找到這這裏的完整文檔:http://codex.wordpress.org/Class_Reference/WP_Query

+0

當我已經把這些代碼將這個? – Donovant 2012-04-14 10:50:25

+0

由你決定。只需用'the_content();'或其他的東西替換'做某事'。 – kpotehin 2012-04-14 10:54:39

相關問題