wp_list_categories pagination

时间:2012-06-28 作者:uknowit2

我想知道我是否可以为wp\\U list\\U类别分页?我尝试了paginate\\u链接,但运气不好。还是有好的解决方法?非常感谢。

<?php   $orderby = \'name\';
    $show_count = 0;
    $pad_counts = 0;
    $hierarchical = 1;
    $taxonomy = \'categories\';
    $title = \'\';
    $exclude = \'16\';

    $args = array(
    \'orderby\' => $orderby,
    \'show_count\' => $show_count,
    \'pad_counts\' => $pad_counts,
    \'hierarchical\' => $hierarchical,
    \'taxonomy\' => $taxonomy,
    \'title_li\' => $title,
    \'exclude\' => $exclude,
    \'hide_empty\' => 0
    );
    ?>
    <ul class="resourcelist">
    <?php wp_list_categories($args); ?>
    </ul> 

1 个回复
SO网友:uknowit2

好的,在wp\\u list\\u categories失败后,我求助于get\\u categories来实现分页。我希望这能帮助别人。

<?php
    $args = array(
            \'taxonomy\' => \'categories\',
            \'orderby\' => \'term_group\',
            \'hide_empty\' => 0,
            \'hierarchical\' => 1,
            \'exclude\' => \'16\',
            \'parent\' => \'0\',
    );
    $categories = get_categories($args);
    $numOfItems = 60;
    $page = isset( $_GET[\'cpage\'] ) ? abs( (int) $_GET[\'cpage\'] ) : 1;
    $to = $page * $numOfItems;
    $current = $to - $numOfItems;
    $total = sizeof($categories);

            echo \'<ul class="content">\';

    for ($i=$current; $i<$to; ++$i) {

        $category = $categories[$i];

        if ($category->name) { echo \'<li><a href="\' . get_term_link($category->slug, \'categories\') . \'" title="\' . sprintf( __( "View all posts in %s" ), $category->name ) . \'" \' . \'>\' . $category->name.\'</a></li>\';}

    }

            echo \'</ul>\';

    unset($category);
    echo paginate_links( array(
        \'base\' => add_query_arg( \'cpage\', \'%#%\' ),
        \'format\' => \'\',
        \'prev_text\' => __(\'&laquo;\'),
        \'next_text\' => __(\'&raquo;\'),
        \'total\' => ceil($total / $numOfItems),
        \'current\' => $page
    ));

    ?>

结束

相关推荐

Why won't pagination work?

我正在使用带有代码的页面模板来显示所有博客帖子:<?php /* Template Name: Blog */ ?> <?php get_header(); ?> <div id=\"main\"> <?php // ACF Page number variable $numposts = get_field(\'number_of_posts_per_page\'); $args =