• Resolved destinedjagold

    (@destinedjagold)


    Hello and good day to everyone.

    I’m having a problem with the pagination function for my category page. Every time I click on the [Next Page] button (with the url “https://www.site.com/blog/main-category/sub-category/page/2/”), it leads me to a [page not found] page (with the url “https://www.site.com/blog/main-category/sample-page/”).

    Here’s the code that I am currently using…

    <?php get_header(); ?>
    
    	<div class="head_content_wrapper">
    		<h2 class="cat_name <?php the_title(); ?>">
    		<?php
    		$categories = get_categories();
    			foreach($categories as $category) {
    				if($category->parent == 0 ){
    					echo '<a id="head_content_link" href="' . get_category_link($category) .'">' . $category->name . '</a>';
    				}
    			}
    		?>
    		</h2>
    	</div>
    
    	<section id="primary" class="site-content">
    		<div id="content" role="main">
    
    		<?php
    			if ( have_posts() ) :
    
    				query_posts( array(
    				 'posts_per_page' => 3,
    				 'paged'=> $paged
    				));
    
    				/* Start the Loop */
    				while ( have_posts() ) : the_post();
    
    					get_template_part( 'content', get_post_format() );
    
    				endwhile;
    
    			endif;
    
    		?>
    
    		<!-- Pagination -->
        <table width="100%" border="0" cellspacing="3" cellpadding="3">
          <tr>
            <td align="left"><?php previous_posts_link('? Previous Page') ?></td>
            <td align="right"><?php next_posts_link('Next Page ?','') ?></td>
          </tr>
        </table>
    		<!--end Pagination-->
    
    		</div><!-- #content -->
    	</section><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    Any help would be greatly appreciated. Thanks.

    Edit: I’ve tried changing the [Setting > Reading > Blog pages show at most] to 3 and 2 and 1, and it still doesn’t solve my problem. :/

Viewing 15 replies - 1 through 15 (of 29 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Does it work with another theme?

    Thread Starter destinedjagold

    (@destinedjagold)

    I am not sure. I can’t change to other themes because we’ve already deleted the themes we weren’t using, and I am afraid to use another theme atm with so many modifications we’ve already done. :/

    We based our current theme from the [twenty-twelve] theme.

    Anyway, I recently tried using this plugin called [WP-PageNavi], but I still am having the same error.

    I am starting to think that this has something to do with the redirect functions in the functions.php. But that’s only a theory at the moment though. :/

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Reinstall TwentyFourteen.

    You CAN switch to another theme without killing your settings. And you need to test that to make sure you messed up the theme (which I suspect is what happened) and that it’s not a network problem.

    Thread Starter destinedjagold

    (@destinedjagold)

    Reinstall TwentyFourteen.

    You CAN switch to another theme without killing your settings. And you need to test that to make sure you messed up the theme (which I suspect is what happened) and that it’s not a network problem.

    I’ve decided to try what you suggested with one of my site as a test.
    This is an example url of what the test site had.

    mysite.com/blog/maintest/

    With this code…

    <?php
    
    get_header(); ?>
    
    	<section id="primary" class="site-content">
    		<div id="content" role="main">
    
    		<?php if ( have_posts() ) : ?>
    
    			<?php
    			$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
    			$args = array(
    				'post_type' => 'post',
    				'posts_per_page' => 1,
    				'paged' => $paged,
          );
    
    			query_posts($args);
    
    			/* Start the Loop */
    			while ( have_posts() ) : the_post();
    
    				get_template_part( 'content', get_post_format() );
    
    			endwhile;
    
    			echo paginate_links( $args );
    			?>
    
    		<?php else : ?>
    			<?php get_template_part( 'content', 'none' ); ?>
    		<?php endif; ?>
    
    		</div><!-- #content -->
    	</section><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    When I click on it, it leads me to this address…

    mysite.com/blog/maintest/page/2/

    And it doesn’t show me a [page not found] error, however, it doesn’t update the contents nor the ‘page number’ on the pagination…

    Anyway, on my main Category Page, it has this as the url…

    mysite.com/blog/main/sub/

    When I hover on the next page button, the link is this…

    mysite.com/blog/main/sub/page/2/

    However, when I click on it, my site redirects me with a “page not found” error.

    mysite.com/blog/main/sample-page/

    WordPress threw me out of the <sub> page and returned me to the <main> page. Maybe there’s something in the functions.php that is doing this?

    Thread Starter destinedjagold

    (@destinedjagold)

    After looking at my functions.php, I found a code for pagination. However, it looked strangely familiar. I believe someone before me added this code before I took over this project and they have yet to test it.

    I wonder if I should remove it or simply update it though. I’ll try and remove it and see what happens. Anyway, here’s the code…

    // Numbered Pagination
    if ( !function_exists( 'wpex_pagination' ) ) {
    
    	function wpex_pagination() {
    
    		$prev_arrow = is_rtl() ? '→' : '←';
    		$next_arrow = is_rtl() ? '←' : '→';
    
    		global $wp_query;
    		$total = $wp_query->max_num_pages;
    		$big = 999999999; // need an unlikely integer
    		if( $total > 1 )  {
    			 if( !$current_page = get_query_var('paged') )
    				 $current_page = 1;
    			 if( get_option('permalink_structure') ) {
    				 $format = 'page/%#%/';
    			 } else {
    				 $format = '&paged=%#%';
    			 }
    			echo paginate_links(array(
    				'base'			=> str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    				'format'		=> $format,
    				'current'		=> max( 1, get_query_var('paged') ),
    				'total' 		=> $total,
    				'mid_size'		=> 3,
    				'type' 			=> 'list',
    				'prev_text'		=> $prev_arrow,
    				'next_text'		=> $next_arrow,
    			 ) );
    		}
    	}
    
    }

    Edit: Removing that code from functions.php didn’t fix my issue, unfortunately. :/

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    And none of that answered the question of “Without your code, using the default theme, does pagination work?”

    I promise, that’s ALL I’m asking you to test right now, and it’s a simple yes or no answer.

    Yes, pagination works with TwentyFourteen

    OR

    No, pagination still fails with TwentyFourteen

    That will tell us where to go next.

    Thread Starter destinedjagold

    (@destinedjagold)

    “using the default theme, does pagination work?”

    I tried again, this time, using the default twentyfourteen theme and page templates without any modifications. I went to the front page of a test site, clicked on one of the categories in the category list in the sidebar, and it loaded the category page.

    This is an example url of what I had in twentyfourteen’s category page.

    https://www.test.com/blog/Canada/School/category/

    I have two posts in the test site, and I’ve set it to only display one post at a time, so the pagination is on the bottom of the post.
    https://oi62.tinypic.com/11r3qty.jpg

    But when I click on page 2, it throws me to a “page not found” page. :/

    https://www.test.com/blog/Canada/sample-page/

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Thank you. FYI: You could have just said “I tested on TwentyFourteen and pagination still doesn’t work.” Seriously, that’s all I was trying to get the answer to! ??

    What’s the content of your .htaccess?

    Thread Starter destinedjagold

    (@destinedjagold)

    Here’s the .htaccess code that our site has.

    AuthUserFile /var/www/html/blog/.htpasswd
    AuthGroupFile /dev/null
    AuthName "Enter User name and password"
    AuthType Basic
    require valid-user
    
    RewriteEngine On
    RewriteBase /blog/
    RewriteRule ^index\.php$ - [L]
    
    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    RewriteRule . index.php [L]
    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Hrm. Have you tried resaving the permalinks? Or different permalinks?

    Thread Starter destinedjagold

    (@destinedjagold)

    I take it that there’s nothing wrong with the .htaccess, right? ‘Cause I was planning to include that in my list of suspects for not getting this pagination in the category page to work…

    Anyway, resaving? What do you mean?

    Anyway, I tried changing the permalinks on the test site that we have.

    Changing it to [default] with our test site (www.test.com/blog/canada/), clicking on one of the category (www.test.com/blog/canada/cat1/) only leads me to a complete replica template of the blog’s homepage (www.test.com/blog/canada/).

    Changing it to [date and name], [month and name], [numeric] and [post name] only gives me a “This is somewhat embarrassing, isn’t it?” message on the category page (www.test.com/blog/canada/cat1/).

    And oh, I don’t know if this is going to help, but the pagination in the post page seems to be okay. I can go to the previous/next posts without problems. :/

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Changing it to [default] with our test site (www.test.com/blog/canada/), clicking on one of the category (www.test.com/blog/canada/cat1/) only leads me to a complete replica template of the blog’s homepage (www.test.com/blog/canada/).

    Wait wait…

    Default permalink for a category is ?cat=cat1 NOT /cat1

    Does THAT work?

    Thread Starter destinedjagold

    (@destinedjagold)

    I am not sure. I don’t know how to change it that way. It has been like that since I took over this project. :/

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    And did you try what I asked?

    As much as it sucks, debugging WordPress, when you have no access to the server, is a lot of us asking YOU to try things. You have to be willing to do this, or be able to make a testbed where you can do it safely, or you will never get anything done.

    Yes, it sucks, but we’re not actually psychic.

    Please try. Change to default permalinks, and try the URL https://www.test.com/blog/?cat=1

    Thread Starter destinedjagold

    (@destinedjagold)

    And did you try what I asked?

    No, I haven’t yet, because as I said, I do not know how to change the category’s permalinks to display that way. :/

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