On my website, I have a custom post type ("foto's"). It contains photo albums which are fetched from Facebook with Facebook Photo Fetcher (plugin). This works great. Unfortunately, this plugin does not allow for pagination. On pages that contain a lot of images this can cause problems (verrrrryyy long load times), such as here.
Because I am using a CPT it seems possible to me to use pagination. Unfortunately I have never used pagination before and I have no idea how to implement it. Is it in the declaration of the cpt, or is it a different function? And how could I make it work only when posts have more than X images?
My guess would be to create a template single-fotos.php
which differs from the default one in that it uses pagination. I do not know how to display pagination when there is more than X images though.
EDIT 1
Building on Matthew's answer, I tried a couple of things. It seems better to edit the plugin, rather than trying building a custom post type.
I added the following lines:
// Look for Next page tag in starttag
if( preg_match('/next=(\d+)/', $retVal['startTag'], $matches) ) $retVal['next'] =$matches[1];
...
// Add default value of next to defaults array
$defaults = array('cols' => 6, //Number of columns of images (aka Number of images per row)
...
'next' => 42); // Can be any number, but preferably a multitude of 'more'
...
// Output photos AND other tags such as more tag and next page
foreach($photos as $photo)
{
//Output this photo (must get rid of [], or WP will try to run it as shortcode)
...
$link = '<a rel="shadowbox[' . $aid . ']" class="fbPhoto" href="'.$photo->source . '" title="'.$caption_with_br.' " ><img src="' . $photo->picture . '" alt="" /></a>';
$retVal['content'] .= "<dl class='gallery-item' style=\"width:$itemwidth%\">";
$retVal['content'] .= "<dt class='gallery-icon'>$link</dt>";
...
$retVal['content'] .= "</dl>\n";
//Move on to the next row?
if( $params['cols'] > 0 && ++$i % $params['cols'] == 0 ) $retVal['content'] .= "<br style=\"clear: both\" />\n\n";
//Insert a more tag?
if( $params['more'] > 0 && $i == $params['more'] ) $retVal['content'] .= "<!--more-->\n\n";
//Insert a next page tag?
if( $params['next'] > 0 && $i == $params['next'] ) $retVal['content'] .= "<!--nextpage-->\n\n";
}
if( $i%$params['cols'] != 0 ) $retVal['content'] .= "<br style=\"clear: both\" />\n\n";
$retVal['content'] .= "</div>\n";
The problem with this is, that the nextpage-tag is only rendered once! After 42 photos (default) the next-tag is inserted, but after the following 42 photos it isn't rendered again. I suppose that is quite normal, but I am not familiar enough with PHP to accomplish that it is rendered every multiplication of the value given (or if not, default value) starting from n=1. How can this be done?
EDIT 2
Note that this should work in combination with a more
tag and that pagination oughtn't show in the snippet. So I do not want in a snippet. Also comments and the respond field should only be placed on the last page.