• Resolved devotee

    (@devotee)


    The title says is. I want to use pagination on my category-pages, but trying to move to page2 just takes me to an empty index.php for some reason. Any ideas?

    The pagination works on the index.php page by the way, which uses more or less the same code as category-x.php does.

    Regards

Viewing 6 replies - 1 through 6 (of 6 total)
  • Have you added the 'paged' and 'posts_per_page' arguments to your query? –

    'paged' => $paged,
    'post_per_page' => get_option('posts_per_page'),

    This is how WP works out what results to get, and it’s done automatically for index.php but not on many other templates.

    Thanks.

    Thread Starter devotee

    (@devotee)

    Maybe thats the error, my code doesnt look exactly like that anyway. This is what my code looks like :
    https://pastebin.com/7DCRgLqT

    Could you be so kind and tell me how I should write it instead? I′m a beginner and not sure where I should fit in that piece of code you wrote.

    Thanks!

    I got this to almost work as I like! The pagination works now with this code:

    <?php if (have_posts()) : ?>
    <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; query_posts(“cat=45&paged=$paged”); ?>
    <?php while (have_posts()) : the_post(); ?>

    Thanks a lot for helping me with that. But one question; this code paginates my page according to the number of posts set in the backend. But If i want to specify my own number of posts in this query, where and what do I type?

    Thanks!

    Ok, can’t be sure as all I can see is this little snippit, but try this – https://pastebin.com/QhG61KdM

    Basically, you were running the query after you had cheked to see if there were any posts, so the query was never being run.

    You may also need to add global $paged to the top of the file/funciton that holds this code, but try without first.

    Thread Starter devotee

    (@devotee)

    Thank you so very much! It works just as I want it!

    You are welcome. Could you please mark this thread as ‘Resolved’ using the drop-down on the right?

    Thread Starter devotee

    (@devotee)

    Yes of course, sorry I forgot ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Pagination loads index.php for category-x.php’ is closed to new replies.