如何按月对帖子进行分组并添加分页?

时间:2014-01-30 作者:user3214264

我想按月份按帖子分组。像这样:

January 2014
职位名称
职位名称

December 2013
职位名称

November 2013
职位名称
职位名称
职位名称
职位名称

我需要有10个月的每页,每个月可以有任何数量的帖子。

我使用WordPress kriesi pagination 将分页添加到网站。

1 个回复
SO网友:nkuldip

Try this code

                                            <?php

                                        $catnam = \'1\';

                                        $paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
                                        // the total of registers to show on each page
                                        $showp = 4;

                                        wp_get_archives("type=monthly&showposts=$showp&paged=$paged");     


                                        while (have_posts() ) : the_post();?>

                                         <h4><a href="<?php echo get_permalink(); ?>"><?php the_title();?></a></h4>

                                         <?php endwhile;?>

                                         <?php
                                            global $wp_rewrite;
                                            $paginate_base = get_pagenum_link(1);
                                            if (strpos($paginate_base, \'?\') || ! $wp_rewrite->using_permalinks()) {
                                                $paginate_format = \'\';
                                                $paginate_base = add_query_arg(\'paged\', \'%#%\');
                                            } else {
                                                $paginate_format = (substr($paginate_base, -1 ,1) == \'/\' ? \'\' : \'/\') .
                                                    user_trailingslashit(\'page/%#%/\', \'paged\');;
                                                $paginate_base .= \'%_%\';
                                            }

                                            echo \'<div id="pagination">\';
                                            echo paginate_links( array(
                                                \'base\' => $paginate_base,
                                                \'format\' => $paginate_format,
                                                \'total\' => $wp_query->max_num_pages,
                                                \'mid_size\' => 10,
                                                \'current\' => ($paged ? $paged : 1),
                                                \'type\' => \'\',
                                                \'prev_text\' => __(\'<p class="readmore">&laquo; Previous</p>\', \'default\'),
                                                \'next_text\' => __(\'<p class="readmore">Next &raquo;</p>\', \'default\'),
                                            ));
                                            echo "</div>";
                                        ?>                
结束

相关推荐

Pagination for user list

我使用get_user() 作用但我需要把结果分页。我试了很多,但没有成功。下面是代码,它没有按预期工作:$args = array( \'meta_query\' => array( array( \'key\' => \'ib_s2member_custom_fields\', \'value\' => trim($_GET[\"country\"]), \'compare\' => \