Sorting images by date or by tag

Comments

4 comments

  • Avatar
    Raya Straus

    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,
    Raya

    0
    Comment actions Permalink
  • Avatar
    Alexis GE

    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
    Comment actions Permalink
  • Avatar
    Alexis GE

    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
    Comment actions Permalink
  • Avatar
    Marissa Masangcay

    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,
    Marissa

    0
    Comment actions Permalink

Please sign in to leave a comment.