【问题标题】:Wordpress - How to add pagination to archive page?Wordpress - 如何将分页添加到存档页面?
【发布时间】:2014-01-30 21:36:05
【问题描述】:

我需要将分页添加到存档页面。每页显示 10 个月。

wp_get_archives('type=monthly&show_post_count=1');

【问题讨论】:

  • 什么样的分页?带号码?上一个/下一个帖子?你尝试了什么?
  • 所以使用 ,正如它所写的那样?
  • 不适用于 wp_get_archives('type=monthly&show_post_count=1');
  • 你有足够的档案来显示分页吗?

标签: wordpress


【解决方案1】:

试试这个

                                            <?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>";
                                        ?>                

【讨论】:

    猜你喜欢
    • 2021-04-09
    • 1970-01-01
    • 2014-03-02
    • 2011-02-18
    • 1970-01-01
    • 1970-01-01
    • 2015-04-11
    • 2017-02-17
    • 1970-01-01
    相关资源
    最近更新 更多