Gallery Pagination by Row

It is definitely possible!!

Ok, here is what I did…

My new loop looks like:

    <?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="https://wordpress.stackexchange.com/questions/54658/<?php echo $post_filter["url']; ?>" class="thickbox" title="https://wordpress.stackexchange.com/questions/54658/<?php echo $post_filter["title']; ?>" alt="https://wordpress.stackexchange.com/questions/54658/<?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 } ?>

My function for the pagination looks like:

<?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]);
}
?>

That’s it!! For me 2440 was the magic number, but you can change it to whatever you like. 2440 is the total width of all of your images…If you want more rows…increase the number, if you want less just decrease the number.