Вы находитесь на странице: 1из 4

2/15/12

Custom Pagination for our WordPress themes

Custom Pagination for your WordPress themes


0

I was recently busy building a new wordpress theme and I decided that I would like to get a better way of showing pagination on my theme pages.

Usually you get the normal wordpress pagination with the next and previous links at top and/or the bottom o around to find a proper solution. A lot of people recommended integrating an existing plugin called WP-PageNavi, but all the posts I saw was integrate and adapt if needed. Part of the solution started with a PHP class called Digg Style Pagination Class which is easy to use and implement, but I needed to add some code for this to work correctly on wordpress themes. If you downloaded the Pagination Class then the code below is how you would use it. 1 2 3 4 5 fnto mpgr$u){ ucin yae(nm $on_ot =w_on_ot(; cutpss pcutpss) $oapss=$on_ot-pbih ttlot cutpss uls;
1/4

you blogging page which really is awful in my opinion. I wanted something to work for me so started Googeli

bit outdated and the plugin was already at version 2.8. So I decided to find a different solution that was easy

teaching ou.net/wordpress/custom-pagination/

2/15/12

Custom Pagination for our WordPress themes

6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 3 0 3 1 3 2 3 3 3 4 3 5

$oapgs=$oapss/$u; ttlae ttlot nm icue'aiaincaspp; nld pgnto.ls.h' $rd=(epy$SRE[HTS])?"tp:/._EVR'EVRNM'._EVR ul !mt(_EVR'TP') hts/"$SRE[SRE_AE]$SRE $urnpg =pe_elc(/^-$/,', $rd;/gttepg nme cretae rgrpae'[09]' ' ul) /e h ae ubr $emln =pe_elc(//ae/09/,',ul) /stcso praik praik rgrpae'\pg\[-]' '$rd; /e utm emln i(mt(cretae)$urnpg =1} fepy$urnpg){cretae ; $ =n pgnto; p e aiain $-ies$oapss; p tm(ttlot) $-lmt$u) p ii(nm; $-cretae$urnpg) p urnPg(cretae; $-prmtrae""; p aaeeNm(p) $-ulredy) p rFinl(; $-tre(praik"ae%";/pg// p agt$emln.pg//)/#ae1 $-so(; p hw) }

Let me break it down for you. First we start by creating a function called m pager($num). Next we need to get the posts count to get the total amount of posts for the current loop and then divide the total by the amount of posts we are showing per page. This is how we do it: 1 2 3 4 5 $on_ot =w_on_ot(; cutpss pcutpss) $oapss=$on_ot-pbih ttlot cutpss uls; $oapgs=$oapss/$u; ttlae ttlot nm

Next we include the pagination class: 1 icue'aiaincaspp; nld pgnto.ls.h'

Next we need to get the current page URL so that we can set the correct pagination number: 1 $rd=(epy$SRE[HTS])?"tp:/._EVR'EVRNM'._EVR ul !mt(_EVR'TP') hts/"$SRE[SRE_AE]$SRE

Next we need to do an str_replace to get the page number we are on:


teaching ou.net/wordpress/custom-pagination/ 2/4

2/15/12

Custom Pagination for our WordPress themes

$urnpg =pe_elc(/^-$/,', $rd; cretae rgrpae'[09]' ' ul)

And then we need to create our own little permalink variable like so: 1 $emln =pe_elc(//ae/09/,',ul) praik rgrpae'\pg\[-]' '$rd;

Our next step is to check if the current page should be page 1 or not: 1 i(mt(cretae)$urnpg =1} fepy$urnpg){cretae ;

All that is left was to set the pagination class variables to call the correct way and display the numbers: 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 $ =n pgnto; p e aiain $-ies$oapss; p tm(ttlot) $-lmt$u) p ii(nm; $-cretae$urnpg) p urnPg(cretae; $-prmtrae""; p aaeeNm(p) $-ulredy) p rFinl(; $-tre(praik"ae%";/pg// p agt$emln.pg//)/#ae1 $-so(; p hw)

In the end all you need to do is add a function call to the end of your page where the pagination is needed like so: 1 <ppi(ucineit(zrae'){zrae(0;}? ?h ffnto_xss'kpgr) kpgr1)

Please keep in mind that you need to set the correct number in the function call so that it will display the correct amount of numbers. WordPress normally sets it to 10 but you could change it for example when you have written a custom loop where you would like to display custom post types and only 6 posts per page.

As you can see this was very easy to use implement let me know if this works for you and if you can add on to the code please comment below. m pager

Related Posts:
6 Dirty Reasons Why You Suck At WordPress Theme Development How to Build Your Own Custom WordPress Premium Theme Admin Part 2 How To Build Your Own Custom WordPress Premium Theme Admin Part 1 WordPress Stats: Create A Simple Stats Plugin For Your Site Add And Remove WordPress User Profile Fields And Display Them Within Your Theme
teaching ou.net/wordpress/custom-pagination/ 3/4

2/15/12

Custom Pagination for our WordPress themes

About Morn I'm a senior PHP developer that is passionate about WordPress, Coding and Marketing. I'm the owner of teachingyou.net and I hope that you will enjoy my writing and teaching. View all posts by Morn

Li e

Add Ne

Comment

Sort b popular now

Sho ing 0 comments


M Subscribe by email RSS

Trackback URL http://teachingyou.net/wordpress/custom-pagination/trackback/

Proudl powered b WordPress.

teaching ou.net/wordpress/custom-pagination/

4/4

Вам также может понравиться