这绝对是可能的!!
好吧,这就是我所做的。。。
我的新循环如下所示:
<?php $ids = array();?>
<?php foreach(query_posts("category_name=photos&showposts=-1") as $post_blog): ?>
<?php $url = wp_get_attachment_image_src( get_post_thumbnail_id($post_blog->ID), \'gallery-full\' ); ?>
<?php $thumbs = wp_get_attachment_image_src( get_post_thumbnail_id($post_blog->ID), \'gallery-thumbnail\' ); ?>
<?php list($width) = getimagesize($thumbs[0]); ?>
<?php $ids[] = array("id_post" => $post_blog->ID, "width" => $width, \'url\' => $url[0], \'title\' => $post_blog->post_title);?>
<?php endforeach; ?>
<?php $page = isset($_GET[\'paged\'])?$_GET[\'paged\']:0;?>
<?php $post_filters = get_posts_by_paged(2440, $ids, $page);?>
<?php $count = $post_filters[\'count\']; ?>
<div class="gallery">
<?php if($post_filters):?>
<?php foreach($post_filters[\'per_page\'] as $post_filter) : ?>
<a href="<?php echo $post_filter[\'url\']; ?>" class="thickbox" title="<?php echo $post_filter[\'title\']; ?>" alt="<?php echo $post_filter[\'title\']; ?>"><?php echo get_the_post_thumbnail($post_filter[\'id_post\'], "gallery-thumbnail", array("title" => $post_filter[\'title\'], "alt" => $post_filter[\'title\'])); ?></a>
<?php endforeach; ?>
<div class="clear">
<!-- -->
</div>
<?php endif; ?>
</div>
<hr />
<?php if ( $prev = get_previous_posts_link("Previous Page") ) { ?>
<div class="left">
<div class="button"><?php echo $prev ?></div>
</div>
<?php } ?>
<?php global $paged; ?>
<?php if($paged == 0) {
$paged = count($ids) > 20?1:0;
}?>
<?php if ( $next = get_next_posts_link("Next Page",$count)) { ?>
<div class="right">
<div class="button"><?php echo $next ?></div>
</div>
<?php } ?>
我的分页函数如下所示:
<?php
function get_posts_by_paged($width_custom, $posts = array(), $page)
{
$post_per_page = array();
$widths = 0;
$group = array();
foreach($posts as $key => $post)
{
$widths = $widths+$post[\'width\'];
if($widths > $width_custom){
array_push($post_per_page, $group);
//reset
$group = array();
$group[] = $post;
$widths = $post[\'width\'];
}else{
$group[] = $post;
}
//recover last
if(count($posts) == $key+1)
{
array_push($post_per_page, $group);
}
}
$page = $page>0?$page-1:$page;
return array("count" => count($post_per_page), "per_page" => $post_per_page[$page]);
}
?>
就这样!!对我来说,2440是个神奇的数字,但你可以把它改成你喜欢的任何数字。2440是所有图像的总宽度。。。如果需要更多行。。。增加数字,如果你想要更少,就减少数字。