WordPress.org

Ready to get started?Download WordPress

Forums

Help with pagination on custom page?? (10 posts)

  1. moxyma
    Member
    Posted 2 years ago #

    Right now I have a custom page template set up that also acts like a second blog page aside from my default WP blog. I need to have pagination on there but I'm not sure how to go about doing this.

    I would only like to call posts from a particular category, which I have working now. And so then I would only like to have say 10 posts on my custom page. Once it reaches 11 how can I handle that with pagination?

    I need to have the archives of posts for my particular category still have the look of my custom page. I hope I explained this right. :(

    I followed the instructions and used the code for my separate blog page from WPBeginner, at this link http://www.wpbeginner.com/wp-tutorials/how-to-create-a-separate-page-for-blog-posts-in-wordpress

    ..i used the first method if that will help give you more of an idea of what i am trying to do . Well, as you can probably see I am not a coder or anything and have only been using WordPress for a few months now and have found so many resources. So I have read all of the documention from the codex and searched but I still need some help with this as it is so far beyond my skill level. So if anyone could help, it would be very appreciated. :)

  2. stvwlf
    Member
    Posted 2 years ago #

    Try inserting the line I indicated below

    <?php
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    
       // insert this line
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    $wp_query->query('posts_per_page=5'.'&paged='.$paged);
    while ($wp_query->have_posts()) : $wp_query->the_post();
    ?>
  3. moxyma
    Member
    Posted 2 years ago #

    Hi stvwlf. Thank you for recommending that. I tried placing it right after where you indicated but it didn't seem to work :(.

    <?php
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('posts_per_page=2'.'&paged='.$paged);
    query_posts( 'cat=49' );
    while ($wp_query->have_posts()) : $wp_query->the_post();
    ?>

    That is the code I have so far. I used query_posts to only retrieve a certain category for my custom blog page and it works. But I can't get it to only show say 2 posts and then the pagination starts. AND I also need those posts in that category to now show on my default/main blog template.

  4. stvwlf
    Member
    Posted 2 years ago #

    hi

    Your query_posts statement is overwriting the query statement above it. Its one or the other, not both. Here I have combined them.

    <?php
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $wp_query->query("posts_per_page=2&cat=49&paged=$paged");
    while ($wp_query->have_posts()) : $wp_query->the_post();
    ?>
  5. moxyma
    Member
    Posted 2 years ago #

    Hello. Ahh, well that makes sense that it was getting overwritten. Thanks again STV :) It looks like I'm getting a lot closer with your help and making progress. I have three posts and only two posts show from category 49 (because of "posts_per_page=2&cat=49&paged=$paged" I see at the bottom of my custom blog page "Older Entries" which it looks like is using the below code from my theme.

    <div class="alignleft"><?php next_posts_link('<span class="back"></span><span class="backnext">Older Entries</span>')?>

    I click on "Older Entries" but it looks like it just refreshes the page. I'm not taken to a page where I can see all of the posts from category 49. I figured since I have three posts and only two posts show on my custom blog page that once I clicked on Older Entries I would be taken to a page where all three would show up in descending order. I'm sure I'm missing something. This is only my third month using WordPress so I still have a lot to learn. :(

  6. stvwlf
    Member
    Posted 2 years ago #

    Hi

    No, actually you should be taken to a page where the third post is displayed on the page, not all 3 posts. You have told WP to only display 2 posts per page so that is the most you will see on any page. Are you seeing the 3rd post on page 2? That is what the pagination does when its configured correctly.

  7. moxyma
    Member
    Posted 2 years ago #

    I am not seeing the third post. :(. This is what I have done so far in the last 30 minutes. I created two additional posts now having a total of 5. They are all published and in category 49. I named them Post 1, Post 2, Post 3, Post 4, and Post 5.

    Right now I see on my blog page "Post 5" and "Post 4". I see on my address bar BEFORE I click on Older entries a url that looks like this: ?page_id=4 when I click on Older Entries my url in the address bar changes to this:
    ?page_id=4&paged=2. And then on that new page is still only see Post 5 and Post 4. I guess I didn't do it right?

    The code that I have in my custom blog page is the last code that you provided to me. :)

  8. stvwlf
    Member
    Posted 2 years ago #

    hi

    can you please post all the code in that custom page template in a pastebin at http://pastebin.com/ - the post the URL here

    thanks

  9. moxyma
    Member
    Posted 2 years ago #

    Sure. Here is the link that I got from Pastebin.

    http://pastebin.com/kixf2x8p

    I hope this helps. Thank you so much STV :d)

  10. moxyma
    Member
    Posted 2 years ago #

    Hi Steve.. Just wanted to let you know that I THINK I have it working!

    I just removed the line of code - $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

    and I installed a plugin named wp-paginate and it seems to be working! Still testing. :) I'll keep ya posted.

Topic Closed

This topic has been closed to new replies.

About this Topic