Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How to add WP-PageNavi pagination to [gallery] shortcode? WordPress

I have the WP-PageNavi plugin installed but would like to know how I can use it to paginate the built in wordpress gallery shortcode?

For instance I want to upload 100 images and display the gallery in 5 pages of 20 images with pagination to navigate back and forth.

I would prefer not to use another plugin to achieve this as I like WP-PageNavi a lot and have also styled it with css to fit my theme perfectly.

Answers (6)

2011-12-04

Fahad Murtaza answers:

Apparently, this plugin doesn't do gallery paging.

But this plugin does

http://wordpress.org/extend/plugins/paged-gallery/

Please read its FAQ.


julesphoto comments:

Thanks for the input, I would prefer to not use another plugin and work WP-PageNavi in to the solution as it is a great pagination solution.


Fahad Murtaza comments:

OK

2011-12-04

Julio Potier answers:

Hello

i Just read the core code for WP Page Navi and this plugin work for posts only and a gallery is not a post.
So the plugin can not do this work.
Same for the core code for [gallery], there is no way to tell this shortcode "only 20 posts please".
In this 2 core codes, filters exists, i think something can be done ... but using a plugin is the best way to do this ...
;)

2011-12-05

Jatin Soni answers:

Download paginated-gallery plugin from this link http://www.phil-barker.com/2011/04/wordpress-gallery-pagination-plugin/

Than extract and place into plugin folder and activate it.

Now use [ paginated_gallery ] shortcode to get gallery or use standard [ gallery ] shortcode. Note: To use wordpress native shortcode [ gallery ] you must have to define use native gallery option in settings.

All settings can be found in Settings > Paginated Gallery. its very easy.

2011-12-05

nina magbanua answers:

hi,

you can go to you admin and check under settings there's a PageNavi settings. You can update your settings here without setting anything on your code:

Please refer to this link:

http://clip2net.com/s/1njjR

2011-12-06

Francisco Javier Carazo Gil answers:

If you are using galleries with images that are saved into database as attachment, you may try to do this:

<?php
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$wp_query = new WP_Query(array('post_type' => 'attachment',
'paged' => $paged,
'post_per_page' => 10)
);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>

2011-12-07

yves vu answers:

hi julesphoto,
you should create a private page to view your gallery.
a file gallerynew-page.php in folder your theme.
Code as:

<?php
/*
Template Name: gallery Page
*/
?>
<?php get_header(); ?>
<?php $postindex = 1;
$my_query = new WP_Query( array('paged' => get_query_var('paged') ) );
if ( $my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div class="postBox <?php if(($postindex % 3) == 0){ echo 'lastBox';}?>">
<div class="postBoxInner">
<?php
if(has_post_thumbnail()) {
//the_post_thumbnail();?>
<img src="<?php echo get_image_path($post->ID); ?>" alt="<?php the_title(); ?>">
<?php } else {
echo '<img src="'.get_bloginfo("template_url").'/images/nothumb.jpg" alt="No Thumbnail"/>';
}?>

<h2><a href="<?php the_permalink() ?>" ><?php the_title(); ?></a></h2>
</div>
</div>
<?php ++$postindex; ?>
<?php endwhile; ?>
<?php if (function_exists('wp_pagenavi')) wp_pagenavi(array( 'query' => $my_query ));
wp_reset_postdata(); // avoid errors further down the page
?>

<?php else : ?>

<p>Sorry, but you are looking for something that isn't here.</p>

<?php endif;
wp_reset_query();?>

<?php get_footer(); ?>



This code use plugin PageNavi to view gallery and it's good for my projects.
You can config "5 pages of 20 images" in config of PageNavi
Hope useful for you.