Giter Club home page Giter Club logo

wp-pagenavi's Introduction

WP-PageNavi

Contributors: GamerZ, scribu
Donate link: https://lesterchan.net/site/donation/
Tags: navigation, pagination, paging, pages
Requires at least: 3.2
Tested up to: 6.3
Stable tag: 2.94.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Adds a more advanced paging navigation interface.

Description

Want to replace the old ← Older posts | Newer posts → links with some page links?

This plugin provides the wp_pagenavi() template tag which generates fancy pagination links.

Usage

In your theme, you need to find calls to next_posts_link() and previous_posts_link() and replace them.

In the Twentyten theme, it looks like this:

<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>

You would replace those two lines with this:

<?php wp_pagenavi(); ?>

For multipart pages, you would look for code like this:

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

and replace it with this:

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

Go to WP-Admin -> Settings -> PageNavi for configuration.

Changing the CSS

If you need to configure the CSS style of WP-PageNavi, you can copy the pagenavi-css.css file from the plugin directory to your theme's directory and make your modifications there. This way, you won't lose your changes when you update the plugin.

Alternatively, you can uncheck the "Use pagenavi.css?" option from the settings page and add the styles to your theme's style.css file directly.

Changing Class Names

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;
}

Development

Credits

Donations

I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations.

Screenshots

  1. With Custom Styling
  2. Admin - Options Page

Frequently Asked Questions

Error on activation: "Parse error: syntax error, unexpected..."

Make sure your host is running PHP 5. The only foolproof way to do this is to add this line to wp-config.php (after the opening <?php tag):

var_dump(PHP_VERSION);

When I go to page 2, I see the same posts as on page 1!

You're using query_posts() wrong. See The Right Way To use query_posts()

Does PageNavi work with secondary WP_Query instances?

Yes; read this tutorial

How do I ignore the options page?

If you are running a multi-language plugin, you will probably want to ignore the strings in the options page.

You can do that like so:

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

Changelog

2.94.1

  • FIXED: PHP 8.2 warnings

2.94.0

  • NEW: Add args param on wp_pagenavi filter. Props @asadowski10
  • NEW: Improve accessibility of nav links. Props @carlabobak

2.93.4

  • FIXED: Update SCB Framework To Support PHP 8

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
  • Update SCB Framework

2.90

  • Remove po/mo files from the plugin
  • Use translate.wordpress.org to translate the plugin

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
  • updated scbFramework

2.82

  • fixed prev/next links not appearing in some conditions
  • added Hebrew, Georgian and Azerbaijani translations
  • updated 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()
  • updated translations
  • more info

wp-pagenavi's People

Contributors

asadowski10 avatar bookwyrm avatar carlabobak avatar cfoellmann avatar filipiz avatar fusilli avatar lesterchan avatar mahjouba91 avatar njonline avatar pedro-mendonca avatar ramiy avatar scribu avatar tiguan avatar tornako avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wp-pagenavi's Issues

2 pages, second page blank?

I have category-exhibitions.php where I am looping the exhibitions category and now I need the pagination part.

<?php
            $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
            $args = array( 'cat' => 6, 'posts_per_page' => 2, 'paged' => $paged );
            $loop = new WP_Query( $args );
            while ( $loop->have_posts() ) : $loop->the_post();
            ?>
            <div class="news">
                <div class="small-title"><?php echo get_cat_name(6) ?></div>
                <div class="main-title"><?php the_title(); ?></div>
                <div class="details">
                    <p>
                        <?php the_excerpt(); ?>
                    </p>
                </div>
                <div class="posted-datetime"><strong>POSTED ON:</strong> <?php the_time( get_option( 'date_format' ) ); ?>  <a href="<?php the_permalink() ?>">READ MORE <i id="arrow" class="fa fa-angle-right"></i></a></div>
                <div class="red-gray-line" style="width:76%;margin-bottom:5%;">
                    <div class="red-line"></div>
                    <div class="gray-line" style="width:82%;"></div>
                </div>
            </div>

            <?php

            endwhile;

            ?>
<?php wp_pagenavi(array( 'query' => $loop )); ?>

the pagination appears, unfortunately the second page is blank.
any suggestion or help?

Deprecated notices with PHP 8.

Deprecated: Required parameter $nonce follows optional parameter $formdata in /localhost/site/wp-content/plugins/wp-pagenavi/scb/Forms.php on line 65

Deprecated: Required parameter $args follows optional parameter $file in /localhost/site/wp-content/plugins/wp-pagenavi/scb/Cron.php on line 24

I think it's just a matter of re-organising your parameters or defining a default for them.

Page list could use a wrapper for grid displaying

Have a common layout requirement to put the "Prev" link left, "Next" link right and page list in the centre of the page, ideally in a bootstrap layout. Having difficulty aligning the "page link" section as there's no wrapper to hook onto. Can do something with JS but would rather it was native. Unfortunately don't know enough about what the code is doing to offer a suggestion, but if a wrapper could be added, would greatly help with display:grid and the like.

Thanks so much!

Multi-language website

How do I translate the texts for different languages within the same website?
Disclaimer:
Currently using Divi with polylang

Disable parts of the pagination

Is it possible to disable parts of the pagination via options?

For example:

  • Disable the number of pages
  • Disable the first/last page button

Deprecation warning

Hi @lesterchan

WP-SCB-Framework is generating a deprecation warning, because it's using screen_icon().

To fix this you have to update one function:

	protected function page_header() {
		global $wp_version;

		echo "<div class='wrap'>\n";
		if ( version_compare( $wp_version, '3.8.0', '<' ) ) {
			screen_icon( $this->args['screen_icon'] );
		}
		
		echo html( 'h2', $this->args['page_title'] );
	}

I was thinking about posting it there, but SCB wasn't updated for 3 years so we can assume it's abandomed.

Possible to use custom SQL?

Greetings

Is it possible to use Pagenavi when using custom sql (not a custom wordpress query)?

Thanks in advance

Regards

Add page input

As seen on the WP Admin list tables, the pagination looks like this:

<<First <Prev  [ 2 ] Next> Last>>

where [ 2 ] is a text input that displays the current page and lets you jump to a random page.

2 pot files instead of one

There is two problems with the translations.

There are two pot files, one with the right text-domain, but without good configurations in order to allow catalog update and the other with wrong text-domain but good preferences (php functions to read, etc).

@lesterchan Can you fix that please ? I didn't figure out how to clean it, it seems that it's something you've done.

Thank you

All category posts displayed one after the other as one scrollable page

I'm building a WordPress site " http://hazelrowley.com/wordpress1/ " using the Himmelen theme by MagniumThemes.

  1. When clicking the category "News and Events" in the Main Navbar, it shows just the one most recent ("Newest") post excerpt (with a "Continue reading" button) with "Older posts" and "Newer posts" buttons below it ( http://hazelrowley.com/wordpress1/category/events/ ).

  2. When I asked MagniumThemes how when clicking the category "News and Events" in the Main Navbar I could get all the other Older posts (again as excerpts) listed one after the other as one scrollable page, with "Continue reading" buttons but no "Older posts" and "Newer posts" buttons, like here http://chewtonbushlandsassociation.org.au/category/the-history/ … they suggested I install your plugin.

Having installed your WP-PageNavi plug-in, it tells me "In your theme, you need to find calls to next_posts_link() and previous_posts_link() and replace them." MagniumThemes told me which php file had the calls so I replaced them per your installation instructions. But having done so has not made the change I seek described above.

Can you tell me if that is because I have not used filters to change the default Class Names… a task beyond my skill set?

I hope you can help me.

Cheers,
Mark

How to get pagination to work with a WP_User_Query

I am having an issue getting the pagination to work while using the WP_User_Query. Here is what I have that doesn't seem to be working. A couple things to note: I am using this as a custom loop on a page template. You will notice I have tried both the 'page' and 'paged' vars. Neither of them seem to work. I've got pagination working with the standard posts loop as well as with a custom post type elsewhere on this site so I know the plugin works and things are good there. Any help you can provide me would be greatly appreciated. Thanks!

$user_fields = array( 'ID', 'display_name', 'user_email' );
    //$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    $args = array(
        'number' => '1',
        'role__in' => array('Subcriber', 'Editor'),
        'fields' => $user_fields,
        'paged' => $paged
    ); // End Args
}
if ($args){
    $user_query = new WP_User_Query( $args );
}
 if ( ! empty( $user_query->results ) ) :
     foreach ( $user_query->results as $user ) :
        //Display stuff
     endforeach;
    wp_pagenavi( array( 'query' => $user_query ) ); 
endif

Using WP-Page with Timber

It's not an issue, but information that maybe should be added to documentation / FAQ.

I had some problems with getting to WP_PageNavi to work with Timber and custom queries, as it turned out the solution was quite simple and it didn't required any extra queries.

// your query args
$args = [
    'posts_per_page' => $context['config']['posts_per_page'],
    'post__not_in' => $ids,
    'paged' => $paged,
];

// WP query
$posts_wp = new WP_Query( $args );

// passing data for Timber
$posts = Timber::query_posts( $posts_wp );

// setting WP_PageNavi
$context['wp_pagenavi'] = wp_pagenavi(
    [
        'echo' => false,
        'query' => $posts_wp,
    ]
);

than it's just passing inserting {{ wp_pagenavi }} in our template.

Removing wp-pagenavi pagination from feeds

I'm having an issue with only the first page of paginated post being included within a feed.
Trying now to cobble together a workaround but nothing seems satisfactory.

Using a genesis theme that provides for simple hooks using conditionals but unsure of the syntax regarding how to terminate post pagination when that content becomes part of a feed.

what is the opposite of array( 'type' => 'multipart' )

And how much sense does the following make::::::::::
if ( is_single() ) {

if (function_exists('wp_pagenavi')) wp_pagenavi( array( 'type' => 'multipart' ) );

} else {
if ( is_feed( $feeds ) ) {
if (function_exists('wp_pagenavi')) wp_pagenavi();
}
}

No tag for 2.85?

Any change you can tag the 2.85 release, so we can use this reliably via wpackagist?

Thanks!

wp-pagenavi - Force 1st page to use the same patern as the others (/page/1)

I really need some help over here.

The 1st page link of the pagination (WP-pagenavi), when i back to it or click on the "1" number (when its not the current) the link must be "/wordpress/index.php/ajax-fonte/page/0/", but right now, it uses "/wordpress/index.php/ajax-fonte/" and "/wordpress/index.php/ajax-fonte/page/X/" for the other pages. So how can i solve this ?

Feature Request: integrate WP PageNavi Style options since it is abandoned

Hello guys. I use your plugin in several sites in conjunction with WP PageNavi Style. But it happens that that plugin is now abandoned. In fact, it's incompatible with PHP 7:
https://wordpress.org/support/topic/compat-with-php-7-can-you-fix-it-or-is-this-plugin-abandoned/#post-8856810

Wouldn't be nice if the main plugin could integrate those options and by doing that saves us from deploying an outdated plugin? Can you?

I bet the PageNavi should detect if PageNavi Style is running and show an admin warning to let users know they should deactivate the plugin. Even so, I think you can do that in one click, to rename the config in the options table and deactivate the old plugin.

I'm not such a skilled coder. Otherwise, I would send the PR myself :) But I know it's possible.

change get url.

hello, take it easy plugin default url change setting should come.
/page/2/ /page/3/ page url for example /xxx/2 how can we change it as we want.

PHP Strict Error

I am currently using WP-PageNavi 2.83 and I getting a php strict error while logged into the admin terminal.

See screenshot for details.

screen shot 2014-02-05 at 12 07 03

WP-Pagenavi for get_terms

Is there any way we're able to get wp-pagenavi working with get_terms (so a pagination of terms)?
Let me know if you need any help :)

Could pagenavi-css.css be limited to only on needed pages?

I know there is an option to disable the CSS but I'd prefer to use it, however for most projects I only need PageNavi on a few templates. Would it be possible to have wp-pagenavi dynamically enqueue the stylesheet only when wp_pagenavi() is called?

I'm just trying to squeeze every drop of optimization for my projects, and before I do any manual overrides I thought I'd ask.

next/previous button position

Pagination style should be common one.
(Or please give me choice to change)
next/previous(or allows) comes to edge of pagination.
This is more common style and often used on other themes/plugins.
Like this
<next first 3 4 5 6 7 last prev>

Settings to control pagination class names

I'd like to be able to customize the class names output by wp-pagenavi to match class naming conventions and support grunticon svg icons.

Are you open to a pull request that extends the PageNavi settings page with fields for class names for extend, current, page, larger, nextpostslink, previouspostslink, etc... (and updates the core.php file to use them)?

Multiple instances on same page

I am trying to use wp-pagenavi to create multiple pagination instances on the same page. The frontend is a tab layout, with each tab housing the results of a query. This stackoverflow shows it is possible with paginate_links() and the format parameter. Is it possible to pass this parameter into wp_pagenavi()?

Duplicate pages

Description

I discovered a bug recently. It occurs only when larger_page_numbers_multiple option is active.

It seems if the remainder of $total_pages divide by $larger_page_multiple is equal to 0, plugin will render $total_pages value 2 times. I'am not sure tho, maybe it's something different.

Screenshot

Steps to reproduce

Options from wp-pagenavi.php:

$options = new scbOptions( 'pagenavi_options', __FILE__, array(
	'pages_text'    => __( 'Page %CURRENT_PAGE% of %TOTAL_PAGES%', 'wp-pagenavi' ),
	'current_text'  => '%PAGE_NUMBER%',
	'page_text'     => '%PAGE_NUMBER%',
	'first_text'    => __( '&laquo; First', 'wp-pagenavi' ),
	'last_text'     => __( 'Last &raquo;', 'wp-pagenavi' ),
	'prev_text'     => __( '&laquo;', 'wp-pagenavi' ),
	'next_text'     => __( '&raquo;', 'wp-pagenavi' ),
	'dotleft_text'  => __( '...', 'wp-pagenavi' ),
	'dotright_text' => __( '...', 'wp-pagenavi' ),
	'num_pages' => 5,
	'num_larger_page_numbers' => 3,
	'larger_page_numbers_multiple' => 10,
	'always_show' => false,
	'use_pagenavi_css' => true,
	'style' => 1,
) );

Number of pages - exactly 10/20/30 etc.

Thanks for making and maintaining this great plugin! 🙂

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.