我在wordpress(分页系统)的数据库中创建了一个新表
我在wordpress的数据库中创建了一个新表。我还创建了一个新的模板页面来查看新表中的记录,但我想为此数据创建系统分页..
这是我的代码
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 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; ?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议通过在末尾添加 LIMIT 来通过 mysql 查询实现分页。 LIMIT 采用两个整数,第一个指的是偏移量(即要跳过的记录数),第二个指的是要显示的记录数。例如,您的查询将是:
然后在页面底部的页面链接上,您通过 url 传递您想要访问的页面。您还可以通过检查当前页面链接是否与 url 中设置的页面匹配来使当前页面链接变灰。
有道理吗?
埃文
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:
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