• Resolved Dani-Girl

    (@dani-girl)


    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/

Viewing 12 replies - 1 through 12 (of 12 total)
  • 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.

    Thread Starter Dani-Girl

    (@dani-girl)

    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”
    https://localhost/?cat=1

    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.

    Thread Starter Dani-Girl

    (@dani-girl)

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

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

    Thread Starter Dani-Girl

    (@dani-girl)

    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?

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

    Thread Starter Dani-Girl

    (@dani-girl)

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

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

    Check your mail…

    Thread Starter Dani-Girl

    (@dani-girl)

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

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

    Ok – for future reference, I’ve added it to the pastebin at https://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.

    Thread Starter Dani-Girl

    (@dani-girl)

    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.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Category Page – Pagination’ is closed to new replies.