Uutiset:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu
Advertisement:

Show all Pages

Aloittaja The Wizard, lokakuu 23, 2013, 01:32:52 IP

« edellinen - seuraava »

The Wizard

Hello:

I am working on a simple gallery script and would like to add the option to show all thumbnails to the pagination. I have no clue how to do this and was hoping someone could help.

Thanks

Wiz


function GetPageNumbers($entries) {
global $config;

$prev = "«Prev";
$next = "Next»";

$config['totalPages']=Ceil(($entries)/($config['cols']*$config['rows']));

// calculate how and what numbers to print
$start=0; // starting image number
$end=$config['totalPages']-1; // ending image number (total / number image on page)

// cutoff size < page. or . page != last page (otherwise keep above values)
if($config['maxShow'] < $config['page'] || (($config['cols']*$config['rows']*$config['maxShow'])< $entries) ){
// if page >= cutoff size+1 -> start at page - cutoff size
if($config['page'] >= ($config['maxShow']+1) && $config['page'] < $end-$config['maxShow']){ $start = $config['page']-$config['maxShow'];}
elseif($end < $config['page']+$config['maxShow']+1 && $config['totalPages']-1 >= $config['maxShow']*2+1){$start = $config['totalPages']-1-$config['maxShow']*2;}
else{$start=0;} // else start at 0

// if page+cutoff+1 > number of pages total -> end= number of pages total
if( $config['page']+$config['maxShow']+1 > $config['totalPages']-1 ){$end = $entries/($config['cols']*$config['rows']);}
elseif($start == 0 && $end > $config['maxShow']*2){$end = $config['maxShow']*2;}
elseif($start == 0 && $config['totalPages'] <= $config['maxShow']*2){$end = $config['totalPages']-1;}
else{$end = ($config['page']+$config['maxShow']);} //end = page+cutoff+1
}


// number of pages
echo "Page ($config[totalPages]): \n";

// PREV
if(($config['page']-1) >= 0){echo "<a href=\"$_SERVER[SCRIPT_NAME]?page=".($config['page']-1)."\">$prev</a>\n";}
else{echo "$prev\n";}

// divide marker
if($start > 0){echo " ... ";}
else{echo " - ";}

// each of the actual numbers
for($i=$start; $i<=$end ; $i++){
if($config['page']==$i){echo "[".($i+1)."] \n";}
else{echo "<a href=\"$_SERVER[SCRIPT_NAME]?page=$i\">".($i+1)."</a>\n";}
}

// divide marker
if(Ceil($end) < $config['totalPages']-1){echo " ... ";}
else{echo " - ";}

// NEXT
if(($config['page']+1) <= $config['totalPages']-1){echo "<a href=\"$_SERVER[SCRIPT_NAME]?page=".($config['page']+1)."\">$next</a>\n";}
else{echo "$next\n";}

}#-#end GetPageNumbers()

Advertisement: