Category foreach Paging

I figured it out!

After a lot of research and trial and error, I managed to figure out how to get the paging to work for both versions…my original code and the simplified code update.

Original Code Solution:

<?php
    $cat = get_cat_ID("Photos");
    $categories = get_categories("child_of=$cat");

    $limit = 9;

    $total = count($categories);
    $pages = ceil($total / $limit);
    $result = ceil($total / $limit);

    $current = isset($_GET['paged']) ? $_GET['paged'] : 1;
    $next = $current < $pages ? $current + 1 : null;
    $previous = $current > 1 ? $current - 1 : null;

    $offset = ($current - 1) * $limit;
    $categories = array_slice($categories, $offset, $limit);
?>

<?php if (is_array($categories) && count($categories) > 0) : ?>
    <?php foreach ($categories as $category) { ?>
        <?php query_posts("cat=$category->cat_ID&orderby=rand&posts_per_page=1"); ?>
            <?php while (have_posts()) : the_post(); ?>
                <a href="https://wordpress.stackexchange.com/questions/154799/<?php bloginfo("url'); ?>?cat=<?php echo $category->cat_ID; ?>"><?php the_post_thumbnail("gallery-thumb"); ?></a>
            <?php endwhile; ?>
        <?php wp_reset_query(); ?>
        <?php query_posts("cat=$category->cat_ID&orderby=name&posts_per_page=1"); ?>
            <h3><a href="https://wordpress.stackexchange.com/questions/154799/<?php bloginfo("url'); ?>?cat=<?php echo $category->cat_ID; ?>"><?php single_cat_title(); ?></a></h3>
        <?php wp_reset_query(); ?>
        <?php $query = $category->count; ?>
        <?php if ($query == 1) $query .= " Image"; else $query .=" Images"; echo '<p class="center">('.$query.')</p>'; //Album Count ?>
    <?php } ?>
    <?php else : ?>
        <p>I hate to break it to you...but right now there are <strong>no albums available</strong> for viewing, please try again later.</p>
    <?php endif; ?>

    <?php echo "<p>(Page: ". $current . " of " . $result .")</p>"; ?>
        <? if($previous): ?>
            <a href="https://wordpress.stackexchange.com/questions/154799/<?php bloginfo("url'); ?>?paged=<?= $previous ?>">Previous</a>
        <? endif ?>
        <? if($next) : ?>
            <a href="https://wordpress.stackexchange.com/questions/154799/<?php bloginfo("url'); ?>?paged=<?= $next ?>">Next</a>
        <? endif ?>

Code Update Solution:

<?php
    $parent = get_cat_ID("Photos");
    $cats = get_categories("child_of=$parent");

    $limit = 9;

    $total = count($cats);
    $pages = ceil($total / $limit);
    $result = ceil($total / $limit);

    $current = isset($_GET['paged']) ? $_GET['paged'] : 1;
    $next = $current < $pages ? $current + 1 : null;
    $previous = $current > 1 ? $current - 1 : null;

    $offset = ($current - 1) * $limit;
    $cats = array_slice($cats, $offset, $limit);
?>

<?php foreach ($cats as $cat) { ?>
    <?php echo $cat->name; ?>
    <?php $query = $cat->count; ?>
    <?php if ($query == 1) $query .= " Image"; else $query .=" Images"; echo '<p class="center">('.$query.')</p>'; //Album Count ?>
<?php } ?>

<?php echo "<p>(Page: ". $current . " of " . $result .")</p>"; ?>
<? if($previous): ?>
    <a href="https://wordpress.stackexchange.com/questions/154799/<?php bloginfo("url'); ?>?paged=<?= $previous ?>">Previous</a>
<? endif ?>
<? if($next) : ?>
    <a href="https://wordpress.stackexchange.com/questions/154799/<?php bloginfo("url'); ?>?paged=<?= $next ?>">Next</a>
<? endif ?>

The middle sections is where my original code is on both solutions, the top and bottom parts are where most of the changes have been made.

I found the solution here: http://erikeldridge.wordpress.com/2009/01/11/simple-php-paging/ – I just changed the array that he had and added the category array that I have, then configured the paging url and added a “(Page # of #)” to finish it up.

Everything works like a champ!

Thanks,
Josh