简体   繁体   中英

get all posts from all categories with pagination

i have 50 categories and every category have 100 post. i have a page template, on this page i want to show category with 5-5 posts but in pagination. I have used this below code but no any pagination and no any post found only category names coming.

$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();

Use paginate_link And do refer this answer from 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;?>

OR Try This

<?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();

          ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM