WP-PageNavi

Description

要替换旧的 ← 较旧文章 | 较新的文章 →带有某些页面链接的导航链接?

该插件提供了wp_pagenavi()模板标签,它可以生成漂亮的分页链接。

用法

在您的主题中,您需要找到对next_posts_link() 和 previous_posts_link() 的调用并替换它们。

在 Twentyten 主题中,它看起来像这样:

<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyten' ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>

您可以将这两行替换为:

<?php wp_pagenavi(); ?>

对于多页页面,您将查找如下代码:

<?php wp_link_pages( ... ); ?>

并替换为:

<?php wp_pagenavi( array( 'type' => 'multipart' ) ); ?>

转到 WP-管理员 -> 设置 -> 分页导航 >进行配置。

更改CSS

如果需要配置WP-PageNavi的CSS样式,则可以将 pagenavi-css.css 文件从插件目录复制到主题目录,然后在其中进行修改。 这样,更新插件时您不会丢失任何更改。

或者,您可以在设置页面取消选中“使用pagenavi.css”选项,然后将样式直接添加到主题的style.css文件中。

更改Class名称

There are filters that can be used to change the default class names that are assigned to page navigation elements.

Filters

  • wp_pagenavi_class_pages
  • wp_pagenavi_class_first
  • wp_pagenavi_class_previouspostslink
  • wp_pagenavi_class_extend
  • wp_pagenavi_class_smaller
  • wp_pagenavi_class_page
  • wp_pagenavi_class_current
  • wp_pagenavi_class_larger
  • wp_pagenavi_class_nextpostslink
  • wp_pagenavi_class_last

Filter Usage

// Simple Usage - 1 callback per filter
add_filter('wp_pagenavi_class_previouspostslink', 'theme_pagination_previouspostslink_class');
add_filter('wp_pagenavi_class_nextpostslink', 'theme_pagination_nextpostslink_class');
add_filter('wp_pagenavi_class_page', 'theme_pagination_page_class');

function theme_pagination_previouspostslink_class($class_name) {
  return 'pagination__control-link pagination__control-link--previous';
}

function theme_pagination_nextpostslink_class($class_name) {
  return 'pagination__control-link pagination__control-link--next';
}

function theme_pagination_page_class($class_name) {
  return 'pagination__current-page';
}


// More Concise Usage - 1 callback for all filters
add_filter('wp_pagenavi_class_previouspostslink', 'theme_pagination_class');
add_filter('wp_pagenavi_class_nextpostslink', 'theme_pagination_class');
add_filter('wp_pagenavi_class_page', 'theme_pagination_class');

function theme_pagination_class($class_name) {
  switch($class_name) {
    case 'previouspostslink':
      $class_name = 'pagination__control-link pagination__control-link--previous';
      break;
    case 'nextpostslink':
      $class_name = 'pagination__control-link pagination__control-link--next';
      break;
    case 'page':
      $class_name = 'pagination__current'
      break;
  }
  return $class_name;
}

Build Status

开发

鸣谢

Donations

我大部分的空闲时间都花在了创建,更新,维护和支持这些插件上,如果您真的喜欢我的插件并且可以为我赞助几块钱,我将不胜感激。 如果不是随意使用它,则没有任何义务。

屏幕截图

  • 使用自定义样式
  • Admin - Options Page

常见问题

激活错误:”Parse error: syntax error, unexpected…”

确信您的主机正在运行PHP5。唯一安全的方法是将此行添加到wp-config.php中(在<?php标记之后):

var_dump(PHP_VERSION);

当我转到第2页时,我看到的文章与第1页相同!

您使用错了 query_posts()。 请参见使用 query_posts()的正确方法

Does PageNavi work with secondary WP_Query instances?

是; 阅读本教程

如何忽略选项页面?

如果您正在运行多语言插件,则可能要忽略选项页面中的字符串。

您可以这样做:

<?php wp_pagenavi( array( 'options' => PageNavi_Core::$options->get_defaults() ) ); ?>

Reviews

2020年7月25日
I have been using this plugin years ago on a news website, and always been happy with it. Didn't have another website suitable for this kind of navigation until now, just set it up (easy!) and loving it again. (Also, the second website is ClassicPress -- no issues.) Thank you!
2020年4月29日
I have been using this years and never left a review. Awesome awesome plugin, thanks.
2019年3月28日
Bom dia. Gostaria da ajuda de vocês. Procurei muito, mas muito mesmo, algum vídeo ou tutorial que ensinasse a instalar e configurar o Plugin wp-pagenavi no especificamente no meu tema que é OCEAN-WP, mas não encontrei. Vocês poderiam me dar um passo-a-passo especificamente nesse tema? Eu ficaria muito agradecido.
阅读所有的135评价

Contributors & Developers

“WP-PageNavi” 是开源软件。 以下人员对此插件做出了贡献。

Contributors

“WP-PageNavi” 已翻译成51 语言环境。 感谢译者的贡献。

将“WP-PageNavi”翻译成您的语言。

Interested in development?

Browse the code, check out the SVN repository, or subscribe to the development log by RSS.

更新日志

2.93.3

  • FIXED: Update SCB Framework To Remove contextual_help

2.93.2

  • NEW: Bumped to WordPress 5.4
  • FIXED: Ensure Action Links is always an array

2.93.1

  • FIXED: Duplicated Settings Saved admin_notices

2.93

  • Remove screen_icon from SCB.

2.92

  • Add title attr to pages link. Props @Mahjouba91.

2.91

  • Validate text option against kses
  • 更新 SCB Framework

2.90

  • Remove po/mo files from the plugin
  • 使用translate.wordpress.org翻译插件

2.89.1

  • FIXED: before and after args

2.89

  • NEW: wrapper_tag option to allow other HTML tag besides DIV and wrapper_class option to allow other class name besides wp-pagenavi. Props @Mahjouba91.

2.88

  • NEW: Added filters for altering class names. Props @bookwyrm

2.87

  • NEW: Uses WordPress native uninstall.php

2.86

  • NEW: Bump to 4.0
  • NEW: Added rel=next and rel=previous

2.85

  • FIXED: “Use pagenavi-css.css” & “Always Show Page Navigation” in the options are not being saved

2.84

  • FIXED: Updated scb framework to fix scbAdminPage incompatible error

2.83

  • added ‘echo’ parameter
  • added Estonian and Bengali translations
  • 已更新 scbFramework

2.82

  • fixed prev/next links not appearing in some conditions
  • added Hebrew, Georgian and Azerbaijani translations
  • 已更新 scbFramework

2.81

  • require an explicit type; fixes bugs with multipart pages

2.80

  • support for multi-part pages and user queries
  • moved prev/next links before/after first/last links
  • more info

2.74 (2011-02-17)

  • added ‘smaller’ and ‘larger’ classes
  • added $query arg to wp_pagenavi()
  • 已更新翻译
  • 更多信息