Sorting images by date or by tag
Hi, i would like to know how i can implement a function to sort my images by date or by an added tag, i explain:
I wish to add a 'New-product' tag so when [people enters my website they can see new products first, of course all new products are uploaded recently so a sort by upload date is good enough, i wish to know if i am clear but most importantly, i am a newbie on programming, i only have a set of libs classes wich i use to upload my images to database and no more.
Another option is a way t implement it via a Sort by date button or something, my page uses Mediaboxes jquery plugin to display the images on each prodcut page.
I guess i need some professional advice here with very clear instructions on how i accomplish this task.
Thank you in advance.
-
Hi Alexis,
Thank you for contacting us.
At the moment we sort by upload date in our media library, showing the newest images first.
Moreover, you can use the Admin API's listing method which returns a list of your resources sorted by their upload date. You can change the direction of the results by setting the parameter, direction. However, this does require some technological know how. For more information please take a look at the following link- https://cloudinary.com/documentation/admin_api#browse_resources
Hope this helps, please let me know if you have any further questions.
Thanks,
Raya0 -
Thank you Raya for your response but images on my website are not displaying the way you point, newer images are being displayed at the bottom. What do you think would be the best approach to fix this? I am a bit lost.
It would also be really cool if i can order my images by tag, but no idea if this is possible, so i am evaluating my subscription plkan and the possibility to move to anotyher system than cloudinary.
0 -
Here is a sample page: http://www.inoplay.com.mx/mobiliario-urbano/basureros-para-parques
Here is the code am using to load album on my category pages:
private function read_album($album = "", $nextcursor = "", $dte = "")
{
$api = new \Cloudinary\Api();
$data = array(
"type"=>"upload",
"tags"=>true,
"keywords"=>true,
"max_results"=>500,
"context"=>true
);
if ($dte>"") {
$data["start_at"] = $dte;
$data["direction"] = "dsc";
} else {
$data["prefix"] = $album;
}
if ($nextcursor>"") {
$data["next_cursor"] = $nextcursor;
}
$result = $api->resources($data);
foreach ($result["resources"] as $dta) {
self::$cloudinary_dta[] = $dta;
}
self::$cloudinary_info["rate_limit_reset_at"] = date("Ymd His", $result->rate_limit_reset_at);
self::$cloudinary_info["rate_limit_allowed"] = $result->rate_limit_allowed;
self::$cloudinary_info["rate_limit_remaining"] = $result->rate_limit_remaining;
if (isset($result["next_cursor"])) {
$this->read_album($album, $result["next_cursor"], $dte);
}
}The question, is here where i should insert some kind of image order or sorting parameter?.
0 -
Hi Alexis,
You can choose the way in which you would like to list the dates by the "direction" parameter in which Raya had mentioned previously. By default, we go by descending order which lists by most recently uploaded resources. However, you can pass in the parameter "direction"=>"asc" in your $data array to reverse the order of your listed resources if desired.
Regarding sorting by tags, you would want to write your own sorting method because the tag's value will be an array so there are many different ways in which you could sort the tags. For example, you could sort each resource's tags array and then sort all of the resources by the first tag in their array, etc. So this would be more of your preference in how you want them to be sorted.
I hope this helps, please let me know if you have any further questions.
Cheers,
Marissa0
Post is closed for comments.
Comments
4 comments