Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #1225999

    Hi Mike,
    You helped me a few days ago on this thread: https://kriesi.at/support/topic/product-grid-limit-nimber-of-products/
    I told you it was ok because it did what I wanted on the 3 concerned pages, but I didn’t see there was a big issue on other pages…
    Indeed, when the function is active, all pages pagination are limited to 5 pages (see example on the page in private content).
    Moreover, at the bottom of pages, page number is not highlighted when active, and text “Page 1 of 5”, “Page 2 of 5” and so on, is hidden.
    Could you please help me on this?
    Thanks a lot!

    #1227112

    Hey fcp,

    Thank you for the update.

    Instead of using the script, maybe we can use this css code to hide the rest of the pagination.

    .pagination .pagination-meta, .pagination a:nth-child(1), .pagination a:nth-child(n+6) {
         display: none !important;
    }

    Best regards,
    Ismael

    #1227345

    Hi Ismael,
    Thanks for your reply.
    Maybe it could be a solution, but I tried to adapt your code to a specific page like this:
    .page-id-5494 .pagination .pagination-meta, .page-id-5494 .pagination a:nth-child(1), .page-id-5494 .pagination a:nth-child(n+8) {
    display: none !important;
    }
    …and it doesn’t work.
    It limits the number of pages to 3, I don’t know why.
    And I would prefer to keep arrows to next pages and last page and the pagination-meta. That’s the reason why Mike’s function was a great idea, but maybe it only needs some adjustments…

    #1228353

    Hi,

    Thank you for the update.

    We also found this filter, which might help adjust the number of total pages shown in the pagination.

        // define the woocommerce_pagination_args callback 
    	 function avf_filter_woocommerce_pagination_args( $array ) { 
            $array['total'] = 5;
            return $array; 
        }; 
    
        add_filter( 'woocommerce_pagination_args', 'avf_filter_woocommerce_pagination_args', 10, 1 ); 
    

    Please remove the browser cache after adding the snippet.

    Best regards,
    Ismael

    #1228387

    Hi Ismael,
    Thanks for your reply.
    I can see you already added this code to my functions.php file, but it doesn’t work.
    Furthermore, I would need to apply this limitation to only three pages on my website…

    #1229365

    Hi,

    The filter doesn’t work because the theme, it turned out, overrides the woocommerce pagination and so we have to override the default pagination instead. Sorry about that.

    Please add this code in the functions.php file:

    // https://pastebin.com/02Y4UzQ8

    Inside that function, you’ll see this block of code:

          if(is_page(array( 731, 5494, 2345))) {
                $pages = 5;
            }
    

    Inside the is_page array are the IDs of the pages where you need to limit the pagination. Just include the actual IDs of the pages in your installation.

    Best regards,
    Ismael

    #1229425

    Hi,
    I looked for the pastebin clip in your functions.php, I didn’t see it so I added it and since your “pages” are actually “archives” I changed the “IF” statement to this:

    if(is_archive(array( 99))) {
    			$pages = 5;
    		}

    because the term for the archive is “99”, but it still is not working well, I will have to research more unless @Ismael sees the error and can correct 🙂

    PS, I also commented out the woocommerce pagination function because I understood from above that this was not the issue.

    Best regards,
    Mike

    #1229500

    Hi Ismael, hi Mike,
    Lot of information today :-D

    Ismael, I tried to add my page ID in your function, but it doesn’t work.

    Mike, I’m not sure to understand what you mean about page/archive and 99… I think the page I need to limit the pagination is really a page and note an archive. This page is in private content and its ID is 5480.
    Anyway, I tried with this:

    		if(is_archive(array( 5480))) {
    			$pages = 5;
    		}

    …but it limits pagination of all pages of my website.

    I thank you a lot if you could find the issue, but if it’s too complicated, cause now there is only one page to limit the pagination, maybe a CSS solution like the one Ismael tried above could be enough…

    Waiting for your reply guys.

    Thanks a lot for your work!! ;-)

    #1229692

    Hi,
    As I understand your opening post, the reason you were having issues with the solution in the other thread, is because you want it to work on one page only and you want the pagination to display the highlighting for the current page, I adjusted the previous solution to achieve both of these.
    Please clear your browser cache and check.
    This is the new script:

    function custom_pagination(){
      ?>
      <script>
    (function($){
      $(document).ready(function(){
    	var url = document.URL;
    	var theURL = url.split("page")[0];
      	$new_pagination = '<nav class="pagination"><a href="'+theURL+'" class="p1">1</a><a href="'+theURL+'page/2/" class="p2">2</a><a href="'+theURL+'page/3/" class="p3">3</a><a href="'+theURL+'page/4/" class="p4">4</a><a href="'+theURL+'page/5/" class="p5">5</a></nav>'
    if ($("body").is('.page-id-5480')){
    	$( "nav.pagination" ).replaceWith( $new_pagination );
    } else {}
    $('#top:not(.paged-2):not(.paged-3):not(.paged-4):not(.paged-5) .pagination .p1').addClass('current');
    $('#top.paged-2 .pagination .p2').addClass('current');
    $('#top.paged-3 .pagination .p3').addClass('current');
    $('#top.paged-4 .pagination .p4').addClass('current');
    $('#top.paged-5 .pagination .p5').addClass('current');
    });
    })(jQuery);
    </script>
    <?php
    }
    add_action('wp_footer', 'custom_pagination');

    Best regards,
    Mike

    #1229711

    Hi Mike,
    Your new function works great! :-)
    Thank you sooo much for your help!
    Do you think it is possible to display “1 of 5”, “2 of 5”, “3 of 5” and so on like on other pages, or maybe it is too difficult?

    #1229715

    Hi,
    Glad it helps, on your other pages the pagination looks like this:
    2020-07-11_162821.png
    and on the page we are working on I see this:
    2020-07-11_163013.png
    Where do you see “1 of 5”, “2 of 5”, “3 of 5” ?
    In the script above for the pagination links you can change the number “2” to “2 of 5”, for example, like this:

    function custom_pagination(){
      ?>
      <script>
    (function($){
      $(document).ready(function(){
    	var url = document.URL;
    	var theURL = url.split("page")[0];
      	$new_pagination = '<nav class="pagination"><a href="'+theURL+'" class="p1">1 of 5</a><a href="'+theURL+'page/2/" class="p2">2 of 5</a><a href="'+theURL+'page/3/" class="p3">3 of 5</a><a href="'+theURL+'page/4/" class="p4">4 of 5</a><a href="'+theURL+'page/5/" class="p5">5 of 5</a></nav>'
    if ($("body").is('.page-id-5480')){
    	$( "nav.pagination" ).replaceWith( $new_pagination );
    } else {}
    $('#top:not(.paged-2):not(.paged-3):not(.paged-4):not(.paged-5) .pagination .p1').addClass('current');
    $('#top.paged-2 .pagination .p2').addClass('current');
    $('#top.paged-3 .pagination .p3').addClass('current');
    $('#top.paged-4 .pagination .p4').addClass('current');
    $('#top.paged-5 .pagination .p5').addClass('current');
    });
    })(jQuery);
    </script>
    <?php
    }
    add_action('wp_footer', 'custom_pagination');

    But this will change the size of your pagination, and not match the rest of your site.
    Am I understanding correctly?

    Best regards,
    Mike

    #1229719

    No, I’m speaking about this: see screenshot in private content (in the red circle).

    #1229724

    Hi,
    Thanks, I adjusted the script to add that and make the leading number change based on the pagination 😅
    Please clear your browser cache and check.

    This is the updated script:

    function custom_pagination(){
      ?>
      <script>
    (function($){
      $(document).ready(function(){
    	var url = document.URL;
    	var theURL = url.split("page")[0];
    	var countURL = url.split("/")[5]|| "1";
      	$new_pagination = '<nav class="pagination"><span class="pagination-meta">Page '+countURL+' sur 5</span><a href="'+theURL+'" class="p1">1</a> <a href="'+theURL+'page/2/" class="p2">2</a> <a href="'+theURL+'page/3/" class="p3">3</a> <a href="'+theURL+'page/4/" class="p4">4</a> <a href="'+theURL+'page/5/" class="p5">5</a> </nav>'
    if ($("body").is('.page-id-5480')){
    	$( "nav.pagination" ).replaceWith( $new_pagination );
    } else {}
    $('#top:not(.paged-2):not(.paged-3):not(.paged-4):not(.paged-5) .pagination .p1').addClass('current');
    $('#top.paged-2 .pagination .p2').addClass('current');
    $('#top.paged-3 .pagination .p3').addClass('current');
    $('#top.paged-4 .pagination .p4').addClass('current');
    $('#top.paged-5 .pagination .p5').addClass('current');
    });
    })(jQuery);

    Best regards,
    Mike

    #1229763

    You’re a genius, Mike!
    Everything works perfectly now and the topic can definitely be closed.
    Thank you so so much for your work on this!!
    Best regards :-)

    #1229769

    Hi,
    Glad we were able to help, we will close this now. Thank you for using Enfold.

    For your information, you can take a look at Enfold documentation here
    For any other questions or issues, feel free to start new threads in the Enfold forum and we will gladly try to help you :)

    Best regards,
    Mike

Viewing 15 posts - 1 through 15 (of 15 total)
  • The topic ‘Product grid limit number of products – Part 2’ is closed to new replies.