WordPress.org

Ready to get started?Download WordPress

Forums

paginate links (12 posts)

  1. oritzio
    Member
    Posted 1 year ago #

    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?

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    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.

  3. oritzio
    Member
    Posted 1 year ago #

    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(); ?>
  4. keesiemeijer
    moderator
    Posted 1 year ago #

    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

  5. oritzio
    Member
    Posted 1 year ago #

    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?

  6. keesiemeijer
    moderator
    Posted 1 year ago #

    You do have more than ten posts?

    Can we have a link to your site?

  7. oritzio
    Member
    Posted 1 year ago #

    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 ?

  8. keesiemeijer
    moderator
    Posted 1 year ago #

    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 ));
  9. oritzio
    Member
    Posted 1 year ago #

    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>
  10. keesiemeijer
    moderator
    Posted 1 year ago #

    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.

  11. oritzio
    Member
    Posted 1 year ago #

    No.. I don't want to paginate the other categories...

  12. keesiemeijer
    moderator
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic