0

I have the following code that is grabbing directories with images from the server and putting them on a website, sorting them in Alphabetical order. I would like to sort them in mixed order. The Gallery name is the name of the directory on the server. So what I was thinking is if there is a way to put 1,2,3,4 in front of the directories and that than with the CSS to put the first letter from the name in white color this way the digits will be invisible. The problems is how to do it. Any other suggestions are welcome as well.

Here is the PHP code:

for ($x = $offset_start; $x < sizeof($dirs) && $x < $offset_end; $x++)
{
    $offset_current++;
    $thumbnails .= $dirs[$x]["html"];
}

this is the css code which is used for this element:

.gallery em {
    color: #000;
    font-style: normal;
    padding: 2px 5px;
    display: block;
    position: absolute;
    top: 243px;
    left: 25px;
    font-family:TrajanPro-Regular;
    font-size:15px;
    color:#796649;
}

The alleries it self are loaded with a tempalte.php which are called with: <% thumbnails %> so this template is used to show all the different galleries I need to to order in mixed mode only on the main gallery page, inside gallery1/sub galery/ is not needed.

4

2 回答 2

0

for each directory gallery put into a ul

<ul id="files" onload="order();">
  <li>Gallery name</li>
  <li>Gallery name</li>
  <li>Gallery name</li>
</ul>

Then in javascript:

function order(){
var mylist = $('#files');
var listitems = mylist.children('li').get();
listitems.sort(function(a, b) {
   return $(a).text().toUpperCase().localeCompare($(b).text().toUpperCase());
});
$.each(listitems, function(idx, itm) { mylist.append(itm); });
}
于 2013-06-27T19:22:49.273 回答
0

如果您有一组目录/图像,则可以使用sort($array)or natcasesort($array)

于 2013-06-27T19:17:57.080 回答