All pastes #1853382 Raw Edit

WordPress dropdown pagination

public php v1 · immutable
#1853382 ·published 2010-03-26 21:44 UTC
rendered paste body
<?php function _mam_ddpaginate($prevtext='&laquo; PREV ',$nexttext=' NEXT &raquo;',$jumptext=' Jump To: ') {   /* Function to provide Previous/Next page links with a dropdown to jump      to other pages.      Author: Mac McDonald      Contact:  Use the About->Contact Us form at BluegrassMiataClub =dot= com   */   global $wp_query;   $pagelinks = "<div class=\"pagelinks\">";   if(isset($_GET['paged'])){      $page = $_GET['paged'];   } else {      $page = 1;   }   $currpage = $_SERVER['REQUEST_URI'];   //echo "<p>CURRPAGE BEFORE:$currpage</p>";   // We want to reformat currpage so paged= is at the end of the string,   // and relocate any other parameters as necessary.   if (preg_match('/\?paged=\d+\&/',$currpage)) { // ?paged=n is first of multiple     $currpage = preg_replace('/\?paged=\d+\&/','?',$currpage);     $currpage .= '&paged=';   } elseif (preg_match('/&paged=\d+/',$currpage)) { // &paged=n is not first     $currpage = preg_replace('/&paged=\d+/','',$currpage);     $currpage .= '&paged=';   } elseif (preg_match('/\?paged=\d+/',$currpage)) { // ?paged=n is alone     $currpage = preg_replace('/\?paged=\d+/','',$currpage);     $currpage .= '?paged=';   } else { // There is no paged=n parameter     // If query_string exists, use &paged=, else use ?paged= .     if ($_SERVER['QUERY_STRING']) {       $currpage .= '&paged=';     } else {       $currpage .= '?paged=';     }   }   //echo "<p>CURRPAGE AFTER:$currpage</p>";   $numofpages = $wp_query->max_num_pages;   //echo "<p>NUMOFPAGES:$numofpages</p>";   if ($numofpages > 1) {      if($page > 1) {         $pageprev = $page - 1;         $pagelinks .= "<a class=\"pageprevlink\" href=\"" . $currpage .            $pageprev . "\">$prevtext</a>&nbsp;&nbsp;&nbsp;";      }      if(($page < $numofpages)) {         $pagenext = $page + 1;         $pagelinks .= "<a class=\"pagenextlink\" href=\"" . $currpage .              $pagenext . "\">$nexttext</a>&nbsp;&nbsp;&nbsp;";      }      if ($numofpages > 2) {        $pagelinks .= "$jumptext <select onchange='location.href=options[selectedIndex].value'>";        for($i = 1; $i <= $numofpages; $i++){           $pagelinks .= "<option value='$currpage$i'";           if ($i == $page) {              $pagelinks .= ' selected';           }           $pagelinks .= ">&nbsp;$i&nbsp;</option>";        }        $pagelinks .= '</select><br />';     }     $pagelinks .= "($page of $numofpages)";         }   $pagelinks .= "</div>";   //echo '<p>PAGELINKS:'; echo htmlspecialchars($pagelinks); echo '</p>';   return $pagelinks;}?>