Announcement

#1 2017-01-08 01:38:01

Walton
Member
2017-01-08
13

Can I display a list sub-albums by using webapi pwg.categories.getLis?

Hi,

I am a new user of Piwigo and I want to make a simple app with it.

the album structure is like this:

Category1
--sub-album11
--sub-album12
--sub-album13

Category2
--sub-album21
--sub-album22
--sub-album23


I want to display a list of latest sub-albums on the home page, like this:

--sub-album11
--sub-album12
--sub-album13
--sub-album21
--sub-album22
--sub-album23

(order by last updated)

but when I use pwg.categories.getList, it gets parent categories only.

Is there a way to display sub-albums instead?

Thank you!


Piwigo version: 2.8.5
PHP version: 5.5.9
MySQL version: 5.5.50

Offline

 

#2 2017-01-08 09:39:07

eliz82
Member
Romania
2016-04-27
281

Re: Can I display a list sub-albums by using webapi pwg.categories.getLis?

yes, you can with recursive and tree output to true
http://demo.piwigo.com/ws.php?format=re … utput=true
and then you extract only "sub_categories"

a little example:

Code:

<?php
$objXml = new SimpleXmlElement(file_get_contents('http://demo.piwigo.com/ws.php?format=rest&method=pwg.categories.getList&recursive=true&tree_output=true'));
foreach($objXml->item as $value) { //loop the response
  if ($value->sub_categories) { //if item has subcategories
    foreach ($value->sub_categories->category as $value) { //loop the subcategories
      echo strval($value->name) . '<br>' . PHP_EOL; //show the subcategory names
    }
  }
}
?>

Last edited by eliz82 (2017-01-08 10:49:22)

Offline

 

#3 2017-01-08 11:30:40

Walton
Member
2017-01-08
13

Re: Can I display a list sub-albums by using webapi pwg.categories.getLis?

Cool!

Done

Thank you very much!


eliz82 wrote:

yes, you can with recursive and tree output to true
http://demo.piwigo.com/ws.php?format=re … utput=true
and then you extract only "sub_categories"

a little example:

Code:

<?php
$objXml = new SimpleXmlElement(file_get_contents('http://demo.piwigo.com/ws.php?format=rest&method=pwg.categories.getList&recursive=true&tree_output=true'));
foreach($objXml->item as $value) { //loop the response
  if ($value->sub_categories) { //if item has subcategories
    foreach ($value->sub_categories->category as $value) { //loop the subcategories
      echo strval($value->name) . '<br>' . PHP_EOL; //show the subcategory names
    }
  }
}
?>

Offline

 

#4 2017-01-08 12:16:48

eliz82
Member
Romania
2016-04-27
281

Re: Can I display a list sub-albums by using webapi pwg.categories.getLis?

Walton wrote:

order by last updated

i didn't saw this first time when i read. yes you can also order by last updated but is a little more complicated.
PLG already made something similar
http://piwigo.org/forum/viewtopic.php?p … 34#p158834
as you can see he put the result in an array with also the date, then he sort the array.

@edit
you can put the date as key of the array value then you can can use ksort http://php.net/manual/ro/function.ksort.php , i find it more simple

Last edited by eliz82 (2017-01-08 12:26:23)

Offline

 

#5 2017-01-10 07:19:10

Walton
Member
2017-01-08
13

Re: Can I display a list sub-albums by using webapi pwg.categories.getLis?

eliz82 wrote:

Walton wrote:

order by last updated

i didn't saw this first time when i read. yes you can also order by last updated but is a little more complicated.
PLG already made something similar
http://piwigo.org/forum/viewtopic.php?p … 34#p158834
as you can see he put the result in an array with also the date, then he sort the array.

@edit
you can put the date as key of the array value then you can can use ksort http://php.net/manual/ro/function.ksort.php , i find it more simple

Great, that's what I need too.
Thank you!

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact