I created a new table in the database of wordpress (paging system)
I created a new table in the database of wordpress. Also I create a new template page to view the records in the new table, but I want to create a system paging for this data ..
this is my code
global $wpdb;
$querystr = "SELECT * FROM wp_hotel WHERE id_city = ".$_GET['city-id'];
$pageposts = $wpdb->get_results($querystr);
if ($pageposts): ?>
<div class="list_hotels">
<?php 开发者_运维知识库foreach ($pageposts as $post): ?>
<?php setup_postdata($post); ?>
<div class="hotel">
<?php echo 'Hotel Name:'.$post->name-hotel; ?><br />
</div>
<?php endforeach; ?>
</div>
<?php else : ?>
<p><?php _e('No Hotel in this city ..'); ?></p>
<?php endif; ?>
I would recommend implementing paging through the mysql query by adding LIMIT to the end. LIMIT takes two integers, the first of which refers to the offset (that is how many records to skip) and the second to how many records to display. So for example your query would be:
$pageoffset = $_GET['page'] * 10;
$querystr = "SELECT * FROM wp_hotel WHERE id_city = ".$_GET['city-id'] . " LIMIT ". $pageoffset .", 10";
Then on the page links at the bottom of the page you pass through what page you want to go to through the url. You could also grey out the current page link by checking if it matches the page set in the url.
Make sense?
Evan
精彩评论