MarcC Posted October 8, 2012 Posted October 8, 2012 I have a list of businesses that I need to paginate alphabetically, so that there's a menu on the page like: [show All] A B C D E F ... Can anyone recommend a way to do this using the PW API? Thanks!
MarcC Posted October 8, 2012 Author Posted October 8, 2012 Thanks Mats--that looks slightly different. I believe that sets up a single list without pagination, correct? I'm wondering if there's a way to do actual pagination.
SiNNuT Posted October 9, 2012 Posted October 9, 2012 I guess you would adjust a function like that to generate your menu so that is outputs links like <a href="/businesses/A/">A</a> <a href="/businesses/B/">B</a> Then you could use url segments and something like $page->children("title^=$input->urlSegment1"); Anyways, just thinking out loud here. Curious as to see what more seasoned pro's think. That function Mats linked to is efficient, even when you've got a lot of children? In MySQL you would do something like: SELECT DISTINCT LEFT(title, 1) as letter FROM mydatabase ORDER BY letter 1
ryan Posted October 10, 2012 Posted October 10, 2012 I've done this before and used the method SiNNuT mentioned. Made the navigation with something like this: for($n = ord('A'); $n <= ord('Z'); $n++) { $letter = chr($n); echo "<a href='{$page->url}$letter/'>$letter</a> "; } Then pulled the items matching the letter from the URL segment like this (just like SiNNuT): $letter = strtoupper(substr($input->urlSegment1, 0, 1)); if($letter >= 'A' && $letter <= 'Z') { $items = $page->children("title^=$letter"); echo "<h2>Letter: $letter</h2>"; if(count($items)) echo $items->render(); else echo "<p>No items found</p>"; } 4
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now