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

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must get the current page with get_query_var() and add it to the query parameters. Also, you must do the pagination before you reset the query. Try changing this:

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

    to this:

    if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
       elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
       else { $paged = 1; }
       //echo "<p>PAGED:$paged</p>";
    
       query_posts( "cat=$catId_comma_separated&paged=$paged");
       while ( have_posts() ) : the_post();
          echo '<li>';
          the_title();
          echo '</li>';
       endwhile;
       ?>
    
       <div class="navigation">
          <div class="alignleft"><?php previous_posts_link('&laquo; Previous Page') ?></div>
          <div class="alignright"><?php next_posts_link('Next Page &raquo;') ?></div>
       </div>
    
       <?php // Reset Query
       wp_reset_query();

    I’m having a slightly different problem with mine. I’m trying to show a page with just one category, but in doing so I loose out on the “Read More” (which I know is another issue entirely), the pagination, and the ability to click on headlines to read posts.

    Here is the code I’m using.

    <?php
    /**
     * Template Name: Main Podcast, no sidebar(s)
    */
    ?>
    <?php include(TEMPLATEPATH . '/SDP-header.php'); ?>
    
        <div id="main-fullwidth" class="span-24">
    
        <div class="content">
    
    <img src="/wp-content/uploads/2013/10/podbotmed.jpg" width=25% height=25%> 
    
    <?php query_posts('cat=993&showposts='.get_option('posts_per_page')); ?>
    <?php get_template_part('loop', 'page'); ?>
        </div><!-- .content -->
    
        </div><!-- #main-fullwidth-->
    
    <?php get_footer(); ?>

    You can see what happens to it here
    http://www.stolendroids.com/sdpodcast

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘want to get all post from all category with pagination’ is closed to new replies.