【问题标题】:Change default pagination style in wordpress更改 wordpress 中的默认分页样式
【发布时间】:2022-01-24 08:03:10
【问题描述】:

我是 WordPress 的初学者并开始学习它。我正在从现有的父主题设计一个新的子主题。父页面的分页

«   Previous   1   2   3   Next   » 

但我想这样修改:

Page 1 of 45   1   2   3   NEXT   10    20    30    LAST

以下是我的代码:

if (!is_singular()) {
            global $wp_query, $rtp_post_comments;
            if (isset($rtp_post_comments['pagination_show']) && $rtp_post_comments['pagination_show']) {
                if (( $wp_query->max_num_pages > 1)) {                    
                        ?>
                    <nav class="wp-pagenavi"><?php
                    echo "<span class='page-count'>Page 1 of " . $wp_query->max_num_pages . "</span>";                    
                    echo paginate_links(array(
                        'base' => str_replace(999999999, '%#%', esc_url(get_pagenum_link(999999999))),
                        'format' => '?paged=%#%',
                        'current' => max(1, get_query_var('paged')),
                        'total' => $wp_query->max_num_pages,
                        'prev_text' => esc_attr($rtp_post_comments['prev_text']),
                        'next_text' => esc_attr($rtp_post_comments['next_text']),
                        'end_size' => $rtp_post_comments['end_size'],
                        'mid_size' => $rtp_post_comments['mid_size']
                    ));
                        ?>
                    </nav><?php
                }
            } elseif (function_exists('wp_pagenavi')) {
                wp_pagenavi();
            } elseif (get_next_posts_link() || get_previous_posts_link()) {
                    ?>
                <nav class="navigation clearfix">                                  
                    <?php if (get_next_posts_link()) { ?><div class="alignleft"><?php next_posts_link(__('Older Entries')); ?></div><?php } ?>
                    <?php if (get_previous_posts_link()) { ?><div class="alignright"><?php previous_posts_link(__('Newer Entries')); ?></div><?php } ?>
                </nav><?php
            }
        }

我应该在哪里更改?

【问题讨论】:

  • 看起来很复杂,也许这个比较好用:Page 1 of 45 | 1 2 3 10 20 30 NEXT LAST
  • @user2019515 :我已经修改了代码。请检查一下

标签: wordpress pagination wordpress-theming


【解决方案1】:

看看paginate links codex page

paginate_links() 位于 wp-includes/general-template.php。 (不建议编辑核心文件。)

或者你可以试试这个插件:WP-PageNavi,它会提供一个选项,可以在开头添加“第 1 页,共 45 页”。

【讨论】:

    【解决方案2】:

    我发现对于一些自定义的东西,wordpress 的功能是难以理解的。但一个很好的解决方法是:

    global $page, $numpages;
    
    if ( $numpages > 1 ) : 
                    if ( $page == 1 ) {
                        $prev_link = '&nbsp;';
                        $next_link = '<a href="' . get_permalink() . ( $page+1 ) . '">Next Page</a>';
                    } else if ( $page == $numpages ) {
                        $prev_link = '<a href="' . get_permalink() . ( $page-1 ) . '">Prev. Page</a>';
                        $next_link = '&nbsp;';
                    } else {
                        $prev_link = '<a href="' . get_permalink() . ( $page-1 ) . '">Prev. Page</a>';
                        $next_link = '<a href="' . get_permalink() . ( $page+1 ) . '">Next Page</a>';
                    }
                ?>
                <div id="post-pagination">
                    <div class="prev-page"><?php echo $prev_link; ?></div>
                    <div class="spacer"><?php echo $page.' / '.$numpages; ?></div>
                    <div class="next-page"><?php echo $next_link ?></div>
                </div>
    

    这很容易定制、风格和理解。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-21
      • 2023-03-30
      • 1970-01-01
      • 2020-10-02
      • 2020-03-15
      • 2014-04-15
      • 1970-01-01
      • 2012-02-27
      相关资源
      最近更新 更多