2013-09-30 138 views
0

我有50個類別,每個類別都有100個帖子。我有一個頁面模板,在這個頁面上,我想顯示類別與5-5職位,但在分頁。 我已經使用下面的代碼,但沒有任何分頁,沒有任何職位只發現類別名稱。從分類中獲得所有類別的所有帖子

$args = array(
'type'      => 'post', 
'child_of'     => 0, 
'parent'     => '', 
'orderby'     => 'ID', 
'order'     => 'ASC', 
'hide_empty'    => 1, 
'hierarchical'    => 1, 
'exclude'     => '', 
'include'     => '', 
'number'     => '', 
'taxonomy'     => 'category', 
'pad_counts'    => false 
); 

$categories = get_categories($args); 
foreach($categories as $category){ $catId[] = $category->term_id; } 
$catId_comma_separated = implode(",", $catId);  

$myposts = get_posts(array('numberposts' => 5, 'offset' => 0, 'cat' => $catId_comma_separated, 'post_status'=>'publish', 'order'=>'ASC')); 
query_posts("cat = $catId_comma_separated"); 
while (have_posts()) : the_post(); 
echo '<li>'; 
    the_title(); 
    echo '</li>'; 
endwhile; 
// Reset Query 
wp_reset_query(); 
custom_pagination(); 

回答

0

使用paginate_link,做從this question

<?php 
$catPost = get_posts('cat=3&posts_per_page=-1'); //change this 
    foreach ($catPost as $post) : setup_postdata($post); ?> 

<h1><a>"><?php the_title(); ?></a></h1> 
    <?php the_excerpt(); ?> 

<p class="postinfo">Written by: <?php the_author_posts_link(); ?> 
Posted on: <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?> 
Categories: <?php the_category(', '); ?></p> 
<hr /> 
<?php endforeach;?> 

參考這個答案,或者嘗試這

<?php 
// The Query 
query_posts(array ('category_name' => 'your_category_name', 'posts_per_page' => -1)); 

    // The Loop 
    while (have_posts()) : the_post(); 
     echo '<h1>'; 
     the_title(); 
     echo '</h1>'; 
     the_excerpt(); 
     echo ' <p class="postinfo">Written by: '; 
     the_author_posts_link(); 
     echo 'Posted on ' 
     the_date(); 
     echo 'Categories: ' 
     the_category(', '); 
     echo '</p>'; 
     endwhile; ?> 

      <?php 

      // Reset Query 
      wp_reset_query(); 

      ?> 
+0

謝謝。我的自定義分頁與其他代碼一起工作正常。但不能使用此代碼。離開分頁主題。並請告訴我如何顯示與類別名稱的所有職位,只感謝.. –

+0

你想顯示所有類別或任何特定類別的所有職位? –

+0

是的,我想顯示所有類別的所有文章。留下分頁的概念。 但只有一個頁面只有一個類別及其所有帖子。 –

相關問題