How would I modify the album tree module to only (put in the generated list) albums starting with LetterLetterNumber (ie. TK1)
I've tried working with some kind of evaluation, ie. if() statement, etc. But it doesn't seem to work.
<?
function makelist($album,$level){
//print out the list item
?>
<li>
<a href="<?= item::root()->url() ?><?= $album->relative_url() ?>"><?=str_repeat(" ", $level) ?><?= html::purify($album->title) ?></a>
</li>
<?
//recurse over the children, and print their list items as well
foreach ($album->viewable()->children(null, null, array(array("type", "=", "album"))) as $child){
makelist($child,$level+1);
}
}
makelist($root,0);
?>
Posts: 27300
I'm no regex expert as I bet this is some complex example that I can't find but should be doable with a if statement.
just wrap the if statement around the <li> so it does not display.
Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team
Posts: 27
I got it to work, finally, but now I have to figure out how to sort the ul or li elements alphabetically. Anyone know how to do this?
<ul class="treealbumnav" id="list">
<?
function makelist($album,$level){
//print out the list item
if(ctype_alpha($album->title[0]) && ctype_alpha($album->title[1]) && is_numeric(substr($album->title,2,5))){
?>
<li>
<a href="<?= item::root()->url() ?><?= $album->relative_url() ?>"><?= str_repeat(" ", $level) ?><?= html::purify($album->title) ?></a>
</li>
<?
}
//recurse over the children, and print their list items as well
foreach ($album->viewable()->children(null, null, array(array("type", "=", "album"))) as $child) {
makelist($child,$level+1);
}
}
makelist($root,0);
?>
</ul>
Posts: 27300
The fourth parameter of the children function is the sort order.
see if changing:
foreach ($album->viewable()->children(null, null, array(array("type", "=", "album"))) as $child) {
to
foreach ($album->viewable()->children(null, null, array(array("type", "=", "album")), array("title", => "DESC")) as $child) {
Not tested so I might have the syntax off a bit.
Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team
Posts: 27
It doesn't work, must be the syntax...when I implement it, the album tree disappears from the sidebar completely which means it doesn't like something about the code...but I certainly appreciate the attempt!
Posts: 27
Got it to work, just had to take a comma out:
array("title", => "DESC")) had to be array("title => "ASC")) for my uses
Posts: 27300
Great! and thanks for posting back the solution.
Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team
Posts: 181
I'm not a PHP expert, but I think you're looking for something like:
This is a little cleaner to read than the strung-out version, which obviously works too. (Regular expressions are very powerful and worth taking the time to learn!)
Above, ^ means match at the start of the line, [:alpha:] is the class of all alphabetic characters in all international languages, and [:digits:] is the numbers.
PHP docs here: http://www.php.net/manual/en/book.pcre.php
Posts: 27
Now I have another problem...it keeps the list seperate for each album it finds them in. As I said, I am a newbie...would a solution be to recurse over the entire site and save everything as an array, then alphabetize it, then spit that array out into <li>'s?
Please see attached screenshot.
Any ideas or help would be greatly appreciated!
Posts: 693
I have a modified version of Album Tree that recurses over the site and stores it in an array, so that I can manipulate the list of albums before displaying them. (What I do is display a list of the first 60 or so albums, and put the rest in a drop-down selector. This means that the vertical height of the tree is not too great.) But I don't know how to alphabetise the array. I'd have thought that it wouldn't be too hard. Google?
U-G
Posts: 27
well I know you can just run a natsort or sort on it and php will sort it for you. can you share this modified album tree?
Thanks,
Michael
Posts: 693
My version attached. No warranties of any kind. It will show just a drop-down selector on resize pages. On thumb pages it will show a list of the first 60 or so albums, and a drop-down for the rest. The number in the list is less on the root page and more on other thumb pages. It's a bit specialised, and so I'm not proposing to put this on the wiki, also because I think it's based on an older version of Album Tree.
U-G
Posts: 27
That's fine, I just appreciate that you shared it so I can see the code that you used to put it all into an array and manipulate the output.
Posts: 693
It occurred to me that my version might be of wider interest, since it solves a particular problem if you want to use a list of albums rather than a drop-down selector, and you have a lot of albums. But it would need some work and a clean up, since my PHP is *very* rudimentary, and I'd probably need to add an admin page so that you could specify the mix and list length. I'd only think about it if there was enough interest.