Tagged: 

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #761498

    hi! i would like to add next and back arrows in addition to the numbered pagination on a shop page. link below. thanks!

    #763166

    Hey Christina,

    Apologies for the late response.

    Before of all, is necessary that you install and use the Theme Child to avoid further problems. So, if you aren`t using it, check this tutorial: http://kriesi.at/documentation/enfold/using-a-child-theme/

    Now, you need to add this custom code in the functions.php at the Enfold Child:

    
    
    function custom_nav_hooks() {
        remove_action( 'woocommerce_after_shop_loop', 'avia_woocommerce_after_shop_loop', 10);
        add_action( 'woocommerce_after_shop_loop', 'custom_avia_woocommerce_after_shop_loop', 20);
    }
    add_action('wp_head', 'custom_nav_hooks', 1000);
    
    function custom_avia_woocommerce_after_shop_loop()
    {
        global $avia_config;
    
        if(isset($avia_config['dynamic_template'])) return;
    
        if(isset($avia_config['overview'] )) {
    
            echo nav_prev_avia_pagination('', 'nav');
    
        }
        echo "</div></main>"; //end content
    }
    
    /**
    * Displays a page pagination if more posts are available than can be displayed on one page
    * @param string $pages pass the number of pages instead of letting the script check the gobal paged var
    * @return string $output returns the pagination html code
    */
    function nav_prev_avia_pagination($pages = '', $wrapper = 'div') //pages is either the already calculated number of pages or the wp_query object
    {
        global $paged, $wp_query;
        
        if(is_object($pages))
        {
            $use_query = $pages;
            $pages = "";
        }
        else
        {
            $use_query = $wp_query;
        }
        
        if(get_query_var('paged')) {
                $paged = get_query_var('paged');
        } elseif(get_query_var('page')) {
                $paged = get_query_var('page');
        } else {
                $paged = 1;
        }
    
        $output = "";
        $prev = $paged - 1;
        $next = $paged + 1;
        $range = 1; // only edit this if you want to show more page-links
        $showitems = ($range)+1;
    
        
        if($pages == '') //if the default pages are used
        {
            //$pages = ceil(wp_count_posts($post_type)->publish / $per_page);
            $pages = $use_query->max_num_pages;
            if(!$pages)
            {
                $pages = 1;
            }
    
            //factor in pagination
            if( isset($use_query->query) && !empty($use_query->query['offset']) && $pages > 1 )
            {
                $offset_origin = $use_query->query['offset'] - ($use_query->query['posts_per_page'] * ( $paged - 1 ) );
                $real_posts = $use_query->found_posts - $offset_origin;
                $pages = ceil( $real_posts / $use_query->query['posts_per_page']);
            }
        }
        
        $method = "get_pagenum_link";
        if(is_single())
        {
            $method = "avia_post_pagination_link";
        }
    
    
    
        if(1 != $pages)
        {
            $output .= "<$wrapper class='pagination'>";
            $output .= "<span class='pagination-meta'>".sprintf(__("Page %d of %d", 'avia_framework'), $paged, $pages)."</span>";
            $output .= ($paged > 2 && $paged > $range+1 && $showitems < $pages)? "<a href='".$method(1)."'>«</a>":"";
            $output .= ($paged > 1 && $showitems < $pages)? "<a href='".$method($prev)."'>‹</a>":"";
    
            
    
            for ($i=1; $i <= $pages; $i++)
            {
                if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
                {
                    $output .= ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".$method($i)."' class='inactive' >".$i."</a>";
                }
            }
    
            $output .= ($paged < $pages && $showitems < $pages) ? "<a href='".$method($next)."'>›</a>" :"";
            $output .= ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) ? "<a href='".$method($pages)."'>»</a>":"";
            $output .= "</$wrapper>\n";
        }
    
        return $output;
    }
    
    

    So, if you check this part of the code: http://prntscr.com/elrto1 – you need to understand that the arrows depend on the quantity page, with this code, the arrows will appear with 2 pages ($range = 1) and ($shoitems = ($range)+ 1). – So, if you want that the arrows appear with 3 pages, you need to replace the $range = 1 by $range = 2.

    Let me know if it works :)

    Best regards,
    John Torvik

    #782508

    Hi! Sorry, I’m just now seeing this. It did work, thanks for your help!

    #782763

    Hi,

    Great, glad we could help. Please open a new thread if you should have any further questions or problems.

    Best regards,
    Rikard

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘woocommerce pagination’ is closed to new replies.