• I’m using a numbered pagination in my wordpress. The code and the result is pasted below

    function kriesi_pagination($pages = '', $range = 2)
    {
         $showitems = ($range * 2)+1;  
    
         global $paged;
         if(empty($paged)) $paged = 1;
    
         if($pages == '')
         {
             global $wp_query;
             $pages = $wp_query->max_num_pages;
             if(!$pages)
             {
                 $pages = 1;
             }
         }
         if(1 != $pages)
         {
             echo "<div class='navigation'>";
             if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>«</a>";
             if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>‹</a>";
    
             for ($i=1; $i <= $pages; $i++)
             {
                 if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
                 {
                     echo ($paged == $i)? "<a class='pagination-link selected' href='".get_pagenum_link($paged)."'>".$i."</a>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
                 }
             }
    
             if ($paged < $pages && $showitems < $pages) echo "<a class='pagination-link' href='".get_pagenum_link($paged + 1)."'>›</a>";
             if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>»</a>";
             echo "</div>\n";
         }
    }

    The result:

    <div class='navigation'>
    <a class='pagination-link selected' href='http://localhost/'>1</a>
    <a href='http://localhost/?paged=2' class='inactive' >2</a>
    <a href='http://localhost/?paged=3' class='inactive' >3</a>
    <a href='http://localhost/?paged=4' class='inactive' >4</a>
    </div>

    Is it possible to remove the http://localhost/ from pagination links to get result like this <a href='/?paged=2'>2</a>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Not easily, no. And to try to do so would be highly inadvisable. WordPress does not function in a predictable fashion using relative urls. Stick to absolute urls.

    Thread Starter muhammadwaqas

    (@muhammadwaqas)

    I’ve found a solution. But it doesn’t include the custom styling of pagination links.

    function oenology_paginate_archive_page_links( $type = 'plain', $endsize = 1, $midsize = 1 ) {
        global $wp_query, $wp_rewrite;
        $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
    
        // Sanitize input argument values
        if ( ! in_array( $type, array( 'plain', 'list', 'array' ) ) ) $type = 'plain';
        $endsize = (int) $endsize;
        $midsize = (int) $midsize;
    
        // Setup argument array for paginate_links()
        $pagination = array(
            'base' => @add_query_arg('paged','%#%'),
            'format' => '',
            'total' => $wp_query->max_num_pages,
            'current' => $current,
            'show_all' => false,
            'end_size' => $endsize,
            'mid_size' => $midsize,
            'type' => $type,
            'prev_text' => '<<',
            'next_text' => '>>'
        );
    
        if( $wp_rewrite->using_permalinks() )
            $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );
    
        if( !empty($wp_query->query_vars['s']) )
            $pagination['add_args'] = array( 's' => get_query_var( 's' ) );
    
        echo paginate_links( $pagination );
    }

    Source: http://wordpress.stackexchange.com/questions/17401/how-to-get-category-tag-in-url-for-pagination-links?answertab=votes#tab-top

    The result appears like this:

    <span class='page-numbers current'>1</span>
    <a class='page-numbers' href='/?paged=2'>2</a>
    <span class="page-numbers dots">…</span>
    <a class='page-numbers' href='/?paged=4'>4</a>
    <a class="next page-numbers" href="/?paged=2">>></a>

    Can we change rewrite the html markup in this function?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘A little help with numbered pagination?’ is closed to new replies.