我想出来了!
经过大量的研究和反复尝试,我终于想出了如何让分页在两个版本中都能正常工作。。。我的原始代码和简化代码更新。
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="<?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="<?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="<?php bloginfo(\'url\'); ?>?paged=<?= $previous ?>">Previous</a>
<? endif ?>
<? if($next) : ?>
<a href="<?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="<?php bloginfo(\'url\'); ?>?paged=<?= $previous ?>">Previous</a>
<? endif ?>
<? if($next) : ?>
<a href="<?php bloginfo(\'url\'); ?>?paged=<?= $next ?>">Next</a>
<? endif ?>
中间部分是我的原始代码在这两个解决方案上的位置,顶部和底部是大部分更改的位置。
我在这里找到了解决方案:http://erikeldridge.wordpress.com/2009/01/11/simple-php-paging/ - 我只是更改了他拥有的数组并添加了我拥有的类别数组,然后配置了分页url并添加了“(第#页,共#)页”来完成它。
一切都像冠军一样!
谢谢,乔希