假设我想使用 $wpdb 类从数据库中检索图像位置,这样我就可以创建一个图像库。我有这段代码,但是当我按“下一步”时,链接似乎没有去任何地方。我错过了什么吗?
<?php
global $wpdb;
$wpdb->show_errors();
$offset = 0;
if( isset($_GET['page']) && !empty($_GET['page']) ){
$offset = ($_GET['page']-1) * 10; // (page 2 - 1)*10 = offset of 10
}
$pics = $wpdb->get_col("SELECT pic_thumb_url FROM wp3_bp_album
WHERE owner_type = 'user' ORDER BY title DESC
LIMIT 10 OFFSET $offset"
);
//LIMIT shows 10 results per page
//OFFSET will 'skip' this number off results. On page 1 the offset is 0 on page 2 it is 10 (if 10 results per page)
foreach($pics as $pic) :
echo '<a href ="'. '#' .'" > <img src="' . $pic . '">' . '</a>';
endforeach;
/*
pagination
*/
?>
<a href="/community/?page=<?php echo $_GET['page']-1 ?>">previous</a>
<a href="/community/?page=<?php echo $_GET['page']+1 ?>">next</a>
我可以用这个实现分页吗?