Jump to content

Is alphabetized pagination possible?


MarcC
 Share

Recommended Posts

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!

Link to comment
Share on other sites

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
  • Like 1
Link to comment
Share on other sites

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>";
}
  • Like 4
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...