• Hi,

    I am pulling items from a database table (not wp) and want to display them in a paginated way. The method I used on my old php pages worked well but I’m moving the site to wordpress.

    I’ve created a page template containing the code and have based a page on that template. The page correctly displays the first page of items and the pagination links (previous 1 2 3 next) and they are clickable, but the links don’t work (404 error).

    I’m not quite sure how to correctly paginate the results so that they work. I’ve had a look at paginate_links() but don’t fully understand how to use it. I can just about find my way around php but am no expert.

    Grateful for any help.

    Here’s the code used to produce the pagination on the old site:

    // Make the links to other pages, if necessary.
    if ($pages > 1) {
    
    	// Add some spacing and start a paragraph:
    	echo '<br /><p>';
    
    	// Determine what page the script is on:
    	$current_page = ($start/$display) + 1;
    
    	// If it's not the first page, make a Previous button:
    	if ($current_page != 1) {
    		echo '<a href="items.php?s=' . ($start - $display) . '&p=' . $pages . '">Previous</a> ';
    	}
    
    	// Make all the numbered pages:
    	for ($i = 1; $i <= $pages; $i++) {
    		if ($i != $current_page) {
    			echo '<a href="items.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a> ';
    		} else {
    			echo $i . ' ';
    		}
    	} // End of FOR loop.
    
    	// If it's not the last page, make a Next button:
    	if ($current_page != $pages) {
    		echo '<a href="items.php?s=' . ($start + $display) . '&p=' . $pages . '">Next</a>';
    	}
    
    	echo '</p>'; // Close the paragraph.
    
    } // End of links section.
Viewing 1 replies (of 1 total)
  • At least part of the problem is the use of ‘&p=’ . $pages to add the page number.

    WordPress uses ‘p=’ to designate a post ID. You should change to ‘&mypage=’.

Viewing 1 replies (of 1 total)
  • The topic ‘paginating query results’ is closed to new replies.