Auto selecting chosen post-per-page
I've created the ability to have posts per page on a gallery of images.
It's working fine but I wanted to add a little feature, but I can't figure
out an elegant solution.
If a user selects a specific number, say 200, I wanted the select box to
automatically show the chosen number on subsequent pages. So the user can
see the change happen.
I'm kind of new to PHP so maybe I'm missing an obvious trick. I know I
could do a massive if else statement for each option like this:
<?php if($posts == 25) { ?>
<option value="">Pics Per Page</option>
<option value="25" selected>25 Pics</option>
<option value="50">50 Pics</option>
<option value="100">100 Pics</option>
<option value="200">200 Pics</option>
<?php } else if($posts == 50 ) { ?>
<option value="">Pics Per Page</option>
<option value="25">25 Pics</option>
<option value="50" selected>50 Pics</option>
<option value="100">100 Pics</option>
<option value="200">200 Pics</option>
<?php } else if... etc. etc.
But this is a bit long winded and I'm sure there's a more elegant solution?
No comments:
Post a Comment