2013-09-30 89 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

是的,我想显示所有类别的所有文章。留下分页的概念。 但只有一个页面只有一个类别及其所有帖子。 –

相关问题