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

pagination - paginate_links with select option

programmeradmin0浏览0评论

This function output :

<<NEXT [SELECT] PREV>>

i need this :

<option value="link/page1">Page 1</option>
<option value="link/page2">Page 2</option>

how do I convert this function to this?

function yorumlariSayfala ( $args = array() ) {
global $wp_rewrite;

if ( ! is_singular() )
    return;

$page = get_query_var('cpage');
if ( !$page )
    $page = 1;
$max_page = get_comment_pages_count();
$defaults = array(
    'base' => add_query_arg( 'cpage', '%#%' ),
    'format' => '',
    'total' => $max_page,
    'current' => $page,
    'echo' => true,
);
if ( $wp_rewrite->using_permalinks() )
    $defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged');

$args = wp_parse_args( $args, $defaults );
$page_links = paginate_links( $args );

if ( $args['echo'] )
    echo $page_links;
else
    return $page_links;
}

This function output :

<<NEXT [SELECT] PREV>>

i need this :

<option value="link/page1">Page 1</option>
<option value="link/page2">Page 2</option>

how do I convert this function to this?

function yorumlariSayfala ( $args = array() ) {
global $wp_rewrite;

if ( ! is_singular() )
    return;

$page = get_query_var('cpage');
if ( !$page )
    $page = 1;
$max_page = get_comment_pages_count();
$defaults = array(
    'base' => add_query_arg( 'cpage', '%#%' ),
    'format' => '',
    'total' => $max_page,
    'current' => $page,
    'echo' => true,
);
if ( $wp_rewrite->using_permalinks() )
    $defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged');

$args = wp_parse_args( $args, $defaults );
$page_links = paginate_links( $args );

if ( $args['echo'] )
    echo $page_links;
else
    return $page_links;
}
Share Improve this question edited Jun 27, 2019 at 12:12 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Jun 27, 2019 at 11:39 Batuhan AygunBatuhan Aygun 276 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Here is the snippet for archive navigation with previous and next link along with the select dopwdown. Select will contain the list of all pages and page url as value of option. onChange is used to redirect page when select option is changed. You can use following code and modify as per your need.

function wpso_custom_archive_navigation() {
    global $wp_query;
    if ( is_singular() ) {
        return;
    }
    if ( $wp_query->max_num_pages <= 1 ) {
        return;
    }
    $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
    $max = intval( $wp_query->max_num_pages );

    // Previous link.
    if ( get_previous_posts_link() ) {
        printf( '%s', get_previous_posts_link( 'Previous' ) );
    }

    echo '<select onChange="window.document.location.href=this.options[this.selectedIndex].value;">';
    for ( $i = 1; $i <= $max ; $i++ ) {
        echo '<option value="' . esc_url( get_pagenum_link( $i ) ) . '" ' . selected( $i, $paged ) . '>';
        echo 'Page ' . $i;
        echo '</option>';
    }
    echo '</select>';

    // Next link.
    if ( get_next_posts_link() ) {
        printf( '%s', get_next_posts_link( 'Next' ) );
    }
}
发布评论

评论列表(0)

  1. 暂无评论