WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Category Page - Pagination (13 posts)

  1. Dani-Girl
    Member
    Posted 2 years ago #

    I'm creating my own category.php page and want to be able paginate. however, when I add in the pagination code and test, nothing happens. It continues to list the same articles.

    I've limit the category page to show 5 posts manually (since I set the blog to only show 2 posts), so will want to paginate when there are more than 5 on a page.

    I've set my permalink to /%category%/%postname%/ and I heard that this may cause a problem with pagination.

    My pagination links look like

    /category/(category name)/page/2/

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    I heard that this may cause a problem with pagination.

    Highly unlikely but you could try a quick switch back to the default permalinks just to confirm this.

    What did you base your category.php template file on? I usually find that starting with a copy of archive.php or index.php helps.

  3. Dani-Girl
    Member
    Posted 2 years ago #

    The template set I got had no category.php or archive.php so I had to create at least the category.php (reading the help articles, archive.php isn't really needed)

    I grabbed the pagination code from the index.php. the index/home page has a different design than the category template, so category had to be made from scratch.

    tested with default parmalinks, and it still won't paginate. The link looks like this on "Previous Entries"
    http://localhost/?cat=1

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    Drop a copy of the category.php file into the WordPress pastebin and post the pastebin url here. Perhaps someone will be able to spot the problem and suggest a solution.

  5. Dani-Girl
    Member
    Posted 2 years ago #

    I'm blocked from the Pastebin site. Any other site i can use?

  6. esmi
    Forum Moderator
    Posted 2 years ago #

    Aw shoot! Are you at work? Could you upload the file as a .txt file and then post a download link here?

  7. Dani-Girl
    Member
    Posted 2 years ago #

    Yes, this is for work, and I'm completely blocked from downloading/uploading anything to sites that are not approved. Not even a text file.

    the code is only 39 lines. Can it be posted here?

  8. esmi
    Forum Moderator
    Posted 2 years ago #

    Only code snippets up to 10 lines are allowed here. Give me a minute...

  9. Dani-Girl
    Member
    Posted 2 years ago #

    In the mean time, I just went to my personal site and posted the code there:

    http://www.dani-girl.com/misc/code/

  10. esmi
    Forum Moderator
    Posted 2 years ago #

    Check your mail...

  11. Dani-Girl
    Member
    Posted 2 years ago #

    Alright, i posted the code to my personal blog. Had to make it easy to understand:

    http://www.dani-girl.com/misc/code/

  12. esmi
    Forum Moderator
    Posted 2 years ago #

    Ok - for future reference, I've added it to the pastebin at http://pastebin.com/AxbkhfWM if you want to delete that post. And the fix is pretty easy. You're currently using query_posts( array( 'cat' => 1, 'posts_per_page' => 4) ); (not sure why you want to limit this to only 1 category in a category template file... but hey ho). As soon as you use query_posts(), you over-write the default query and all of its parameters - including the variable that records what page you're on. So you either have to add this variable back into your custom query or you tack your custom query onto the default one - this retaining all of the paging.

    I'd suggest the latter approach here. Try using:

    query_posts( $query_string . '&cat=1&posts_per_page=4' );

    instead.

  13. Dani-Girl
    Member
    Posted 2 years ago #

    OMGoodnes!! thank you that solved it.

    I was given this code:
    query_posts( array( 'cat' => 1, 'posts_per_page' => 4) );

    when I asked about only displaying posts from 1 category (we have no other categories) and to display more than the blog setting (which we have at only 2 entries)

    thanks, that fixed it.

Topic Closed

This topic has been closed to new replies.

About this Topic