I have a picture gallery that is working, I am converting it to a shortcode so the positioning can be flexible and I don't have to copy the code over and over again.
The issue I am having is that the pagination doesn't advance to the next page. The images show, the pagination shows, the page number shows...but when I try and click on page two or three the images, pagination, and page numbers don't change. The URL changes, the content doesn't.
I have a page with some manual code (that works and advances or changes when pagination is clicked).
The site I am working on is: http://joshrodg.com/test/banquet/2017-induction-banquet/. My test shortcode is on top (underneath 2017 Induction Banquet), the one that works, is the bottom one (manual code).
My shortcode looks like: [halloffame rml_folder="16"]
My function looks like:
function picture_gallery($atts){
extract(shortcode_atts(array(
'rml_folder' => 1
), $atts));
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
query_posts("post_status=inherit&post_type=attachment&rml_folder=".$rml_folder."&orderby=title&order=asc&posts_per_page=12&paged=".$paged);
if ( have_posts() ) :
$return_string .= '<div id="album">';
while ( have_posts() ) : the_post();
$return_string .= '<div class="gallery">';
$image = wp_get_attachment_image(get_post_thumbnail_id($post->ID), 'medium');
$return_string .= '<a href="'.wp_get_attachment_url($post->ID).'" class="simplelightbox">'.$image.'</a>';
$return_string .= '<p>'.get_the_title().'</p>';
$return_string .= '</div>';
endwhile;
$return_string .= '</div>';
endif;
$return_string .= '<div id="pagi">';
$return_string .= '<div class="wrap">';
$args = array(
'prev_text' => __('<span class="left"></span><span class="ion-android-arrow-dropleft"></span>'),
'next_text' => __('<span class="ion-android-arrow-dropright"></span><span class="right"></span>')
);
$return_string .= paginate_links($args);
$return_string .= '</div>';
$return_string .= '</div>';
global $wp_query;
$current_page = get_query_var( 'paged' );
$pages = $wp_query->max_num_pages;
$return_string .= '<p align="center">(Page: '.$current_page.' of '.$pages.')</p>';
wp_reset_query();
return $return_string;
}
function register_shortcodes(){
add_shortcode('halloffame', 'picture_gallery');
}
add_action( 'init', 'register_shortcodes');
Because this is working with the manual code, I'm guessing something is not quite right with my shortcode code.
Any ideas?
** UPDATE **
So, on the page http://joshrodg.com/test/banquet/, the pagination is broken, but on http://joshrodg.com/test/banquet/2017-induction-banquet/ the pagination works. 2017-induction-banquet
is the original post, it's a child post of http://joshrodg.com/test/banquet/. On http://joshrodg.com/test/banquet/, I am displaying the content of all my child pages. So, the shortcode itself is working, just not on this page - so there might be something wrong with my loop.
The loop for this page looks like:
<?php query_posts("order=asc&orderby=menu_order&posts_per_page=-1&post_type=page&post_parent=".$post->ID); ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="wrap">
<h2><?php the_title(); ?></h2>
</div>
<p><?php the_content(); ?></p>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
I'm thinking there might be a conflict with the loop in the shortcode and the loop on this page.
The pagination on the original page looks like: http://joshrodg.com/test/banquet/2017-induction-banquet/page/2/
The pagination on the parent page looks like: http://joshrodg.com/test/banquet/page/2/
Not sure if that makes a difference, but figured it's worth mentioning.
Thanks,
Josh
get_query_var( 'paged' )
returns the correct page number?