We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7327
    • 195 Posts
    Hi all,

    Thought it might be useful for people who are looking for a SplitPagination snippet alternative if for some reason they can't use that (ex: I can't seem to use SplitPagination for my custom snippet that's calling Ditto via a $mod->runSnippet function). I've created a simple JQuery function that will clean up the page numbers to show only X and Y amount of pages before and after the current page. This JQuery solution assumes you're simply using Ditto's paginate parameter and default HTML markup:

    DEFAULT PAGINATION OUTPUT:
    
    <p>Showing <strong>[+start+]</strong> - <strong>[+stop+]</strong> of <strong>[+total+]</strong> Articles | Page <strong>[+currentPage+]</strong> of <strong>[+totalPages+]</strong></p> <div id="ditto_pages"> [+previous+] [+pages+] [+next+] </div>
    
    


    JQUERY FUNCTION:

    
    		function fixPagination(paginationContainer, pageLink, currentPageLink, maxPageLinksPrepend, maxPageLinksAppend) {
    			startPageLink = 0;
    			totalPageLinks = $(pageLink).length + 1; //Include current link too
    			currentPageLinkIndex = $(paginationContainer).children().closest(currentPageLink).index();
    
    			endPageLinkPrepend = currentPageLinkIndex - maxPageLinksPrepend - 1;
    			endPageLinkAppend = currentPageLinkIndex + maxPageLinksAppend - 1; 
    			//alert(endPageLinkPrepend + ' ' + endPageLinkAppend);
    
    
    			if (endPageLinkPrepend > 0) {
    				count = 0;
    				for (count = startPageLink; count < endPageLinkPrepend; count++) {
    					//alert(count);
    					$(pageLink + ':eq(' + count + ')').css('display','none');
    				}
    			}
    
    			if (endPageLinkAppend > 0) {
    				count = 0;
    				for (count = endPageLinkAppend; count < totalPageLinks; count++) {
    					//alert(count);
    					$(pageLink + ':eq(' + count + ')').css('display','none');
    				}
    			}
    
    		}
    
    		fixPagination('#ditto_pages', '.ditto_page', '.ditto_currentpage', 3, 3);