WordPress.org

Ready to get started?Download WordPress

Forums

Permalink Custom Structure VS Pagination (3 posts)

  1. MikeArsenault
    Member
    Posted 3 years ago #

    Hello all,

    We have a custom link structure that looks like this:

    /%category%/%post_id%/%postname%/

    We are trying to implement pagination on our category pages. What is happening currently is that we are getting redirected to individual posts based on the page number. We are using a custom category.php page, and here is the code we are using to pull in the post listings:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    $wp_query = new WP_Query("category_name=$category_name&paged=$paged&posts_per_page=30");
    
    if ( have_posts() ) while ( have_posts() ) : the_post();

    Here is an example of a category page in action on our development site:

    http://chud.huddler.com/types/reviews/

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    $wp_query = new WP_Query('category_name=' . $category_name . '&paged=' . $paged . '&posts_per_page=30');

  3. MikeArsenault
    Member
    Posted 3 years ago #

    Thank you esmi for your reply! Your code does the exact same thing as mine, but less efficiently as far as PHP is concerned. PHP uses a concept in programming called String Interpolation, which allows you to insert variables inside of double-quotes. PHP will then automatically know how to take the values of those variables and put them into the string, which will then be passed to the WP_Query object initializer method.

    When you do it with single quotes as you showed above, you are using a technique called Concatenation, which is the piecing together of several small strings into a larger string.

    In the case of the code above, what you wrote and what I wrote accomplish the exact same goal. From PHP's perspective, it has to do more work to handle Concatenation than it does Interpolation, so using Interpolation is always more efficient in this language. And that is definitely not a WordPress thing, it's just how PHP works.

    What I really need is a good tutorial that allows you to see some of the different combinations of Custom URL Structures and pagination. Maybe there is some custom thing I could do to the .htaccess file that handles the redirection that will help?

    What is happening now is that if you try to go to Page 2 of our reviews area, you get redirected to post ID #2 in the single post view and not the actual second page of the review category listing.

    So the URL to get to Page 2 of the results looks like this:

    http://chud.huddler.com/types/reviews/page/2/

    but when you click on that URL, it leads here:

    http://chud.huddler.com/types/columns/interviews/2/interview-john-travolta/

    We are using a plug-in called WP-PageNavi to display our page links, but there doesn't appear to be anything in that plug-in that can be changed to make this work as far as I can tell.

Topic Closed

This topic has been closed to new replies.

About this Topic