All pastes #1854209 Raw Edit

WordPress dropdown pagination

public php v1 · immutable
#1854209 ·published 2010-03-27 23:15 UTC
rendered paste body
<?php function mam_ddpaginate($jumptext=' Jump To: ') {   /* Function to provide a dropdown to jump to other pages.      Use in conjunction with previous/next_posts_link for navigation.      Author: Mac McDonald      Contact:  Use the About->Contact Us form at BluegrassMiataClub =dot= com   Sample Usage:   <div class="navigation">      <div class='alignleft'>         <?php next_posts_link('&laquo; Older Entries') ?>&nbsp;&nbsp;&nbsp;         <?php previous_posts_link('Newer Entries &raquo;') ?>&nbsp;&nbsp;&nbsp;         <?php echo mam_ddpaginate();          echo '<br /><div class="alignleft">';         echo mam_pagesummary(); ?></div>      </div>   </div>   */   global $wp_query,$wp_rewrite;	$numofpages = $wp_query->max_num_pages;   //echo "<p>NUMOFPAGES:$numofpages</p>";   if ($numofpages > 1) {     //echo '<p>wp_query:';print_r($wp_query);echo '</p>';     //echo '<p>permalink_structure:';print_r(get_option('permalink_structure'));echo '</p>';     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;     $currpage = $_SERVER['REQUEST_URI'];     if (!$_SERVER['QUERY_STRING']) $currpage = trailingslashit($currpage);     //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.     // Are we using pretty permalinks?     $pretty = ($wp_rewrite && $wp_rewrite->using_permalinks()) ? TRUE : FALSE;     if (!$pretty) {       if (preg_match('/([?&])paged=\d+(\&)?/',$currpage,$matches)) {         //echo "<p>MATCHES:";print_r($matches);echo "</p>";         if ($matches[1] == '?') {           if ($matches[2] == '&') {             // paged is first, followed by other params             $currpage = preg_replace('/\?paged=\d+\&/','?',$currpage);             $currpage .= '&paged=';           } else {  // ?paged= is alone             $currpage = preg_replace('/\?paged=\d+/','',$currpage);             $currpage .= '?paged=';           }         } else { // &paged=n is not first           $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=';         }       }     } else {   // Using pretty permalinks       // If there is no /page/n/, add page/1/ to $currpage.       if (!preg_match('#/page/\d+#',$currpage)){         if (strpos($currpage,'/?')) {           $currpage = preg_replace('#/\?#','/page/1/?',$currpage);         } else {           $currpage .= 'page/1/';         }       }     }     //echo "<p>CURRPAGE AFTER:$currpage</p>";     $pagelinks = "$jumptext <select onchange='location.href=options[selectedIndex].value'>";     for($i = 1; $i <= $numofpages; $i++){       $pagelinks .= "<option value='";       if ($pretty) {         $thispage = preg_replace('#/page/\d+#',"/page/$i",$currpage);       } else {         $thispage = "$currpage$i";       }       $pagelinks .= "$thispage'";       if ($i == $paged) {         $pagelinks .= ' selected';       }       $pagelinks .= ">&nbsp;$i&nbsp;</option>";     }     $pagelinks .= '</select>';   }   //echo '<p>PAGELINKS:'; echo htmlspecialchars($pagelinks); echo '</p>';   return $pagelinks;   }   function mam_pagesummary() {     global $wp_query;     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;     $numofpages = $wp_query->max_num_pages;     $pagesummary =  "($paged of $numofpages)";     return $pagesummary;   }?>