Hello/Hi/Greetings,
I really need that help, please, please help me , GOD...
How to setup each album first image to representative default?
The default is seems random.
Piwigo version: 2.9.1
PHP version: 7.0.1
MySQL version: 5.55
Piwigo URL: http://testing now.
Offline
please master, need help, thanks very much.
Offline
still waiting that help, master ~~ god ~~ I need you lol
Offline
Hi :-)
They're no option to make this
Offline
ddtddt wrote:
Hi :-)
They're no option to make this
thanks, but it's scripts, must have some where can be edit it ?
Offline
kiwiyak wrote:
ddtddt wrote:
Hi :-)
They're no option to make thisthanks, but it's scripts, must have some where can be edit it ?
You can make plugin for this
Offline
ddtddt wrote:
kiwiyak wrote:
ddtddt wrote:
Hi :-)
They're no option to make thisthanks, but it's scripts, must have some where can be edit it ?
You can make plugin for this
Already have that plugin please ??? lol
No sorry I'haven't this
Offline
This is a feature I wish piwigo had as well.
I am not at all a programmer so writing a php plugin is not possible. But I have come up with my own method to do this and it involves using a combination of SQL queries, a simple bash loop, and the piwigo api 'pwg.categories.setRepresentative' which for me running on localhost, more information is located at: http://localhost/piwigo/tools/ws.htm.
This is all done from a linux terminal. I suppose you could do the same thing on windows with cygwin.
First I get a list of the categories/album ID's:
mysql --user=yourusername -B -N -p -e "SELECT id FROM piwigo.piwigo_categories;" > albumIDs
You use your database username, -B makes the output separated by tab, -N strips out the column names, -p is so it asks for your password, -e is to execute the given SQL query. Then it writes the output to a text file named albumIDs
This text file contains all the ID #'s of your albums.
The next step requires curl and your cookie file for piwigo. I use a firefox addon called CLIget which automatically outputs the cookie in the necessary format.
for SET in `cat albumIDs ` ; do PIC=`mysql -B -N --user=yourusername --p -e "SELECT id FROM piwigo.piwigo_images WHERE storage_category_id=$SET order by path ASC limit 1;"` ; curl --header 'Cookie: pwg_id=18t4c2htj7rtp1p4q57iahgfq4; __zlcmid=fsgLZSGNrIcWIQ' -d "method=pwg.categories.setRepresentative&category_id=$SET&image_id=$PIC" -X POST 'http://localhost/piwigo/ws.php?format=rest' ; done
This is a single line bash script. Sorry I'm not a programmer so I don't know best practice to make things more easily understandable. What it does is:
For each ID in that albumIDs file, do a sql query that SELECTS the ID of all the images with a matching storage_category_id. SORT those images ASC (ascending), and LIMIT the output to the first one.
Then have curl call the piwigo API method 'pwg.categories.setRepresentative' with the the category being the albumID and the image_id being the matching id number from the previous sql query.
You MUST replace the cookie part with your actual piwigo cookie when logged in as an administrator. I included an expired cookie just as an example, it should look similar form. If you use cliget and have it give you a command to download your admin page, you can use the cookie part. Also you need to to use your URL, my piwigo is on localhost.
Once this is all done it will set representative for all the albums which have images in them, to the first one. What it will NOT do is change the representative for parent albums which contain only sub albums. I've figured how to do this as well but I can't find my notes on how I did it. It was not too dificult to do, I think I just looped on the parent albums, selected the representatives from the subalbums and limited it to 1. Parents get their representative from subalbums so if a random first image doesn't bother you then you can stop here. Otherwise if you manage to get my first method I'm sure you could figure out the parent albums.
Sorry for the long explanation. But I'm always a bit nervous when I copy commands into the command line and I have no idea what they are doing. As I said I'm not trained in programming whatsoever and the only first principles I'm working off is a bit of logic and bunch of trial and error. But I hope this helps you at least to finding your own method that makes sense for you.
Last edited by birdlives (2017-08-11 09:05:09)
Offline
I am also looking for a simple way to do this.
Thanks for the guide birdlives. This seems a lot more complicated than it should be.
I was hoping for a simple code edit to change the representative from being random to being the first.
Offline
Maybe I misunderstand what you are after, but this will set the album thumbnail
Choose the pic, and click on "album thumbnail"
Last edited by Knitter (2017-08-13 20:09:10)
Offline
thanks very much,
recently, I'm full check all the php scripts files with piwigo
I notice in 1 php files, handle the representative , it's order by "random", I try to edit it , order by ASC , but it's not work.
I'm wondering, how it's not work even I edited it , upload it ...
Offline
the files is functions.php, I'm edit following (ORDER BY image_id ASC LIMIT 1), not work:
/**
* Set a new random representant to the categories.
*
* @param int[] $categories
*/
function set_random_representant($categories)
{
$datas = array();
foreach ($categories as $category_id)
{
$query = '
SELECT image_id
FROM '.IMAGE_CATEGORY_TABLE.'
WHERE category_id = '.$category_id.'
ORDER BY image_id ASC
LIMIT 1
;';
list($representative) = pwg_db_fetch_row(pwg_query($query));
$datas[] = array(
'id' => $category_id,
'representative_picture_id' => $representative,
);
}
mass_updates(
CATEGORIES_TABLE,
array(
'primary' => array('id'),
'update' => array('representative_picture_id')
),
$datas
);
}
Offline
as my edit, it should be work, but not ... dont know what's wrong
Offline
kiwiyak wrote:
the files is functions.php, I'm edit following (ORDER BY image_id ASC LIMIT 1), not work:
/**
* Set a new random representant to the categories.
*
* @param int[] $categories
*/
function set_random_representant($categories)
{
$datas = array();
foreach ($categories as $category_id)
{
$query = '
SELECT image_id
FROM '.IMAGE_CATEGORY_TABLE.'
WHERE category_id = '.$category_id.'
ORDER BY image_id ASC
LIMIT 1
;';
list($representative) = pwg_db_fetch_row(pwg_query($query));
$datas[] = array(
'id' => $category_id,
'representative_picture_id' => $representative,
);
}
mass_updates(
CATEGORIES_TABLE,
array(
'primary' => array('id'),
'update' => array('representative_picture_id')
),
$datas
);
}
Were you able to figure this out kiwiyak? I'm not very good with PHP but that code you referenced may be for if random representatives are enabled in the config (new random representative every reload which is disabled by default). That may explain why you didn't notice any change.
Offline
not sure, if can be this right now ? why that is SO hard to work ? thanks all and master
Offline