YAXRQCBJFR ?
Subscribe to RSS feed

Home :.: About :.: Contact :.: Archives :.: Bookmarks :.: WishList


I’ve been using the pagebar plugin 0/1 for some time now. Recently I requested on the weblog of the writer of the plugin if he could add a button which would show a random page (here Submit), but unfortunately the writer, latz, didn’t want to implement such a feature.

However, since I have about 800 different pages of postings to show you (which of course noone ever clicks, but what the heck) it is fairly impossible to reach let’s say page 500 without clicking an awful lot of times. Of course a user could just add the page=500 addition to the url in the browser window but I wanted something easily clickable which let’s me and possibly you just get a glimp of some pages I wrote in the past.

So I added the random function to the pagebar. If you have the same need, here is the code:

Add this function to the pagebar php code:

 1: function randomPage($max_page) {
 2: global $pbOptions;
 3:  
 4: if ($pbOptions["pdisplay"] == "never")
 5: return;
 6:  
 7: $text = "I feel lucky!";
 8:  
 9: srand(time());
 10: $random = (rand()%$max_page);
 11:  
 12: echo ' <a href="'.get_pagenum_link($random).'">'.$text.'</a>';
 13: }

And then of course call it at the end:

 1: randomPage($max_page);
 2: echo "</div>";

It would be nicer if I would have added the text to be configurable and the random button to show or not show also in the administration part of the plugin, but since I’m the only user… that seemed pretty pointless.

Hopefully latz will add this functionality some day nevertheless so I can upgrade more easily to new versions of the pagebar without having to add this code each time to the plugin code.

Related posts