1 00:00:00,270 --> 00:00:03,230 Now that we have all our basic parameters set up, 2 00:00:03,230 --> 00:00:05,600 we'll need to do a couple calculations. 3 00:00:05,600 --> 00:00:08,600 First, we want the total number of pages. 4 00:00:08,600 --> 00:00:11,981 So we'll take the total number and divide it by the items per page. 5 00:00:17,510 --> 00:00:21,122 We want this to return the next highest integer value, 6 00:00:21,122 --> 00:00:23,860 rounding up value if necessary. 7 00:00:23,860 --> 00:00:27,900 There's a built in function to do this, and it's called ceil. 8 00:00:27,900 --> 00:00:30,560 So will surround our calculation with a function ceil. 9 00:00:32,450 --> 00:00:36,800 The final calculation we need is to find out how many items to skip for 10 00:00:36,800 --> 00:00:38,420 the current page. 11 00:00:38,420 --> 00:00:40,660 Let's start with some notes. 12 00:00:40,660 --> 00:00:43,730 Remember to start comment lines with double forward slashes. 13 00:00:45,810 --> 00:00:50,191 We want to determine the offset which is 14 00:00:50,191 --> 00:00:55,649 the number of items to skip for the current page. 15 00:01:00,280 --> 00:01:05,044 For example: [BLANK AUDIO] 16 00:01:05,044 --> 00:01:10,172 on page 3 with 8 items per page, 17 00:01:10,172 --> 00:01:15,130 the offset would be 16. 18 00:01:15,130 --> 00:01:16,041 So let's calculator offset. 19 00:01:18,926 --> 00:01:24,196 We'll use current_page- 1 20 00:01:24,196 --> 00:01:30,880 multiplied by the items per page. 21 00:01:30,880 --> 00:01:33,820 Make sure you add parentheses to be sure your calculations are done 22 00:01:33,820 --> 00:01:34,660 in the correct order. 23 00:01:40,350 --> 00:01:44,536 So if our items_per_page is 8 and we're on page 2, 24 00:01:44,536 --> 00:01:49,480 we want to skip the first 8 items that we already show on page 1. 25 00:01:49,480 --> 00:01:55,510 2- 1 =1, multiplied by 8 = 8. 26 00:01:56,530 --> 00:02:01,634 If we were on page 1, we would see 1- 1 = 0, 27 00:02:01,634 --> 00:02:05,520 multiplied by 8 still = 0. 28 00:02:05,520 --> 00:02:09,330 So on our first page, we don't want to skip any items. 29 00:02:09,330 --> 00:02:12,620 If we have less items left than the items per page, 30 00:02:12,620 --> 00:02:15,180 it will show only the remaining items. 31 00:02:15,180 --> 00:02:17,650 For example, if we have 15 items and 32 00:02:17,650 --> 00:02:23,520 we show 10 per page, on the second page we would only see 5 items. 33 00:02:23,520 --> 00:02:27,470 Before we move on to using these new variables to set our limits, 34 00:02:27,470 --> 00:02:31,530 let's set up a couple redirects if our page numbers aren't valid. 35 00:02:31,530 --> 00:02:34,820 We're going to do two things, right after we set our total pages. 36 00:02:36,810 --> 00:02:41,060 Let's start with our comments again, 37 00:02:41,060 --> 00:02:48,540 [BLANK AUDIO] redirect too-large page numbers to the last page. 38 00:02:50,910 --> 00:02:58,410 We also want to redirect too-small page numbers to the first page. 39 00:03:03,640 --> 00:03:05,401 Let's set a conditional for our first redirect. 40 00:03:10,950 --> 00:03:15,262 If the current page is greater than our total pages, 41 00:03:15,262 --> 00:03:19,281 [BLANK AUDIO] let's change these to plural. 42 00:03:23,360 --> 00:03:25,900 Total pages instead of total page. 43 00:03:25,900 --> 00:03:27,819 Then we want to redirect them to our catalog page. 44 00:03:33,721 --> 00:03:37,610 We're going to pass our page number of total pages. 45 00:03:45,820 --> 00:03:49,467 For the second redirect, 46 00:03:49,467 --> 00:03:54,109 if our ($current_page < 1) 47 00:03:54,109 --> 00:03:58,760 we're going to redirect again. 48 00:04:06,830 --> 00:04:08,545 This time setting our page to 1. 49 00:04:09,980 --> 00:04:12,550 We also need to know if we're on a category page. 50 00:04:12,550 --> 00:04:15,215 So let's add a new variable to limit results. 51 00:04:18,380 --> 00:04:19,540 We'll start with a comment. 52 00:04:25,100 --> 00:04:28,000 By default, we don't want to limit our results. 53 00:04:28,000 --> 00:04:31,305 So we'll initialize limit results using an empty string. 54 00:04:35,680 --> 00:04:39,146 Then, we add a conditional to check if we are in a category page. 55 00:04:39,146 --> 00:04:46,133 Using if (!empty($section)). 56 00:04:46,133 --> 00:04:50,670 If we're on a category page, then we wanna redirect them to a category page. 57 00:04:50,670 --> 00:04:59,480 $limit._results = Don't forget the ampersand at the end. 58 00:04:59,480 --> 00:05:01,780 This will allow us to pass the page number as well. 59 00:05:03,610 --> 00:05:06,631 Now, we can add the limit_results variable to our redirects. 60 00:05:27,600 --> 00:05:28,500 Great. 61 00:05:28,500 --> 00:05:31,520 All our variables are set and we're ready to start limiting our pages.