【问题标题】:I created a new table in the database of wordpress (paging system)我在wordpress(分页系统)的数据库中创建了一个新表
【发布时间】:2010-10-04 19:01:43
【问题描述】:

我在 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; ?>

【问题讨论】:

  • 我需要添加分页 .. page(1,2,3,4,5, .. .etc) 但我不知道 .. 因为我使用的是自定义查询或自定义表..对不起我的英语不好..

标签: php wordpress loops


【解决方案1】:

我建议通过在末尾添加 LIMIT 来实现通过 mysql 查询的分页。 LIMIT 接受两个整数,第一个表示偏移量(即要跳过多少条记录),第二个表示要显示多少条记录。例如,您的查询将是:

$pageoffset = $_GET['page'] * 10;
$querystr = "SELECT * FROM wp_hotel WHERE id_city = ".$_GET['city-id'] . " LIMIT ". $pageoffset .", 10";

然后在页面底部的页面链接上,您通过 url 传递您想要访问的页面。您还可以通过检查它是否与 url 中设置的页面匹配来将当前页面链接变灰。

有意义吗?

埃文

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-20
    • 1970-01-01
    相关资源
    最近更新 更多