Tagged: 

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #763794

    hi! my client would like forward and backwards arrows in addition to page numbers in the woocommerce store, how can i add these?

    #763948

    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( '<a href='https://woocommerce.com/?ref=84' target='_blank' rel="nofollow">woocommerce</a>_after_shop_loop', 'avia_<a href='https://woocommerce.com/?ref=84' target='_blank' rel="nofollow">woocommerce</a>_after_shop_loop', 10);
        add_action( '<a href='https://woocommerce.com/?ref=84' target='_blank' rel="nofollow">woocommerce</a>_after_shop_loop', 'custom_avia_<a href='https://woocommerce.com/?ref=84' target='_blank' rel="nofollow">woocommerce</a>_after_shop_loop', 20);
    }
    add_action('wp_head', 'custom_nav_hooks', 1000);
    
    function custom_avia_<a href='https://woocommerce.com/?ref=84' target='_blank' rel="nofollow">woocommerce</a>_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

    #804657

    Hi @johntorvik,

    I was curious about using the arrows myself, but it just gave a Parse Error (blank screen) once the page was reloaded. Did this work for you, @greenbeansdesign?

    #804827

    Hi,

    This thread is old, so, is necessary that you have sure about the theme version and plugins.

    Best regards,
    John Torvik

    #808708

    hi! i just started this thread in march? everything is current…

    #809184

    I agree, @greenbeansdesign :D John, my question was did the solution you gave work?

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.