Thread Starter
oujele
(@oujele)
Just to add, the code below is what I am looking for but it switches between albums. What variables I should use so it would switch between the galleries inside each album?
add_shortcode( 'prev', 'prev_shortcode' );
add_shortcode( 'next', 'next_shortcode' );
function next_shortcode($atts) {
global $post;
ob_start();
next_post_link( '<div class="nav-next">%link</div>', 'Next post link' );
$result = ob_get_contents();
ob_end_clean();
return $result;
}
function prev_shortcode($atts) {
global $post;
ob_start();
previous_post_link( '<div class="nav-previous">%link</div>', 'Previous post link' );
$result = ob_get_contents();
ob_end_clean();
return $result;
}
hi @oujele
There is nothing built into FooGallery to give you that info, but if you add these snippets to your functions.php you can use them to get back the previous and next gallery ID’s based on the current gallery.
function foogallery_album_find_next_gallery_id( $album, $gallery_id ) {
$return = false;
foreach ( $album->galleries() as $gallery ) {
if ( $return ) {
return $gallery->ID;
}
if ( $gallery->ID === $gallery_id ) {
$return = true;
}
}
return null;
}
function foogallery_album_find_previous_gallery_id( $album, $gallery_id ) {
$previous_id = false;
foreach ( $album->galleries() as $gallery ) {
if ( $gallery->ID === $gallery_id ) {
return $previous_id;
}
$previous_id = $gallery->ID;
}
return $previous_id;
}
And then you could use the functions inside a custom album template like this:
echo 'Previous : ' . foogallery_album_find_previous_gallery_id( $current_foogallery_album, $foogallery->ID );
echo 'Next : ' . foogallery_album_find_next_gallery_id( $current_foogallery_album, $foogallery->ID );