最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to make a pagination with dropdown selection?

programmeradmin0浏览0评论

This is the code for the dropdown pagination. It uses a js controller too, but it works fine, so, I’m not adding it.

$total = $wp_query->max_num_pages;
// only bother with the rest if we have more than 1 page!
if ( $total > 1 )  {
    // get the current page
    if ( !$current_page = get_query_var('paged') ){
      $current_page = 1;
    }   
    // structure of "format" depends on whether we're using pretty permalinks
    $format = 'page/%#%/';
    $linkarray = paginate_links(array(
      'base' => str_replace( 'page/9999999/', '%_%', esc_url( get_pagenum_link( 9999999 ) ) ),
      'format' => $format,
      'current' => 0,
      'show_all' => true,
      'total' => $total,
      'mid_size' => 4,
      'prev_next' => False,
      'type' => 'array'
    ));
 
    $urlarray = array();
 
    foreach($linkarray as $value){
        $pieces = explode(' ',$value);
        foreach($pieces as $piece){
            if (substr(strtolower($piece),0,4) == 'http'){
                $urlarray[] = $piece;
            }
        }
    }
 
    echo '<div style="text-align: center">(Or jump to page ';
    echo '<select id="paginationpageselectcontrol" name="paginationpageselectcontrol">' . "n";
    $pagecounter = 1;
    foreach($urlarray as $url){
        echo '<option value="' .  $url . '"' . (($pagecounter == $current_page)?' selected':'') . '>' . $pagecounter . '</option>' . "n";
        $pagecounter = $pagecounter + 1;
    }
    echo '</select>' . "n";
    echo ' of ' . $total . ')</div>';
}

I think the error is around here:


    $urlarray = array();
 
    foreach($linkarray as $value){
        $pieces = explode(' ',$value);
        foreach($pieces as $piece){
            if (substr(strtolower($piece),0,4) == 'http'){
                $urlarray[] = $piece;
            }
        }
    }

发布评论

评论列表(0)

  1. 暂无评论