WordPress.org

Support

Support » How-To and Troubleshooting » paginate links

paginate links

  • oritzio

    @oritzio

    Hello,

    I’m showing up in my index.php all my latest posts
    and i would like to put in the bottom the pagination for older posts

    Now i saw this function:
    paginate links
    http://codex.wordpress.org/Function_Reference/paginate_links

    I put that code
    <?php echo paginate_links( $args ) ?>
    and the parameters but it doesn’t seem to work,
    Can someone help me to see what I’m missing?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Moderator keesiemeijer

    @keesiemeijer

    Can you paste and submit the full code of index.php into a pastebin.com and post the link to it here? see the Forum Rules for posting code and using the pastebin.

    oritzio

    @oritzio

    Ok, sorry..

    For example, I’m showing my posts and after thati copy and paste the array code:

    <?php get_header(); ?>
    
    	    <!-- Posts Begin Here -->
                 <?php query_posts('cat=4&showposts=10&order=DESC');?>
    		     <?php while (have_posts()) : the_post();?>
                     <div class="quotesgrid">
                         <div class="date"><?php the_date(M . " " . d); ?></div>
                         <div class="quotes">
                             <h2><?php the_title(); ?></h2>
                             <?php the_content(); ?>
                         </div><!-- quotes -->
                     </div><!-- quotesgrid -->
                 <?php endwhile; ?>
    
             <?php $args = array(
                        'base'         => '%_%',
                        'format'       => '?page=%#%',
                        'total'        => 1,
                        'current'      => 0,
                      );
                    ?>
    
             <?php echo paginate_links( $args ) ?> 
    
    <?php get_footer(); ?>
    Moderator keesiemeijer

    @keesiemeijer

    Try it without the query_posts and with the code example from the paginate_links page:

    <?php get_header(); ?>
    
    	    <!-- Posts Begin Here -->
    
    		     <?php while (have_posts()) : the_post();?>
                     <div class="quotesgrid">
                         <div class="date"><?php the_date(M . " " . d); ?></div>
                         <div class="quotes">
                             <h2><?php the_title(); ?></h2>
                             <?php the_content(); ?>
                         </div><!-- quotes -->
                     </div><!-- quotesgrid -->
                 <?php endwhile; ?>
    
             <?php
    global $wp_query;
    
    $big = 999999999; // need an unlikely integer
    
    echo paginate_links( array(
    	'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    	'format' => '?paged=%#%',
    	'current' => max( 1, get_query_var('paged') ),
    	'total' => $wp_query->max_num_pages
    ) );
    ?>
    
    <?php get_footer(); ?>

    And with this in your theme’s functions.php to query the home page:

    function my_post_queries( $query ) {
      // not an admin page and is the main query
      if (!is_admin() && $query->is_main_query()){
        if(is_home()){
          $query->set('posts_per_page', 10);
          $query->set('cat', 4);
        }
      }
    }
    add_action( 'pre_get_posts', 'my_post_queries' );

    http://www.billerickson.net/customize-the-wordpress-query/
    http://codex.wordpress.org/Pagination#Removing_query_posts_from_the_main_loop

    oritzio

    @oritzio

    Thanks for the help… I’ve put that code also in the function file and in my index file and it doesn’t work for me.

    I’ve got to mention that I’ve started to work on my theme from a blank template.

    Do you have any idea why I still can’t see the pagination?

    Moderator keesiemeijer

    @keesiemeijer

    You do have more than ten posts?

    Can we have a link to your site?

    oritzio

    @oritzio

    Okay, you’re totally right…

    Your code is working perfect, haha..
    I just figured.

    But still I’m having the same question,
    How can I load a different category of posts in the same page ?

    Moderator keesiemeijer

    @keesiemeijer

    Doesn’t $query->set('cat', 4); show only posts from category 4 (ID)?

    If you want to show multiple categories you can use ‘category__in’.:

    $query->set('category__in', array( 4, 8 ));

    oritzio

    @oritzio

    I would like to know how to load in the same page more than 1 category,
    for example:

    <div id="category3">
    load posts from ID 3
    </div>
    <div id="category4">
    load posts from ID 3
    </div>
    Moderator keesiemeijer

    @keesiemeijer

    The trouble is that you can only paginate one loop (the main loop). For what you want you need multiple loops, but only one can be paginated.

    oritzio

    @oritzio

    No.. I don’t want to paginate the other categories…

    Moderator keesiemeijer

    @keesiemeijer

    here is an example: http://pastebin.com/v2DnNXES
    Use the functions.php code to show only category 4 posts for the main paginated loop.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘paginate links’ is closed to new replies.
Skip to toolbar