By default phpwebgallery set one representative picture per category, but this representative picture is always the same...
This small modification permits to change the representative picture of a category each time a sub category is browsed.
Tested with phpwebgallery 1.4.1.
File to modify: ./include/category_subcats.inc.php SEARCH and REPLACE: SELECT id, name, date_last WITH: SELECT id, nb_images, name, date_last THEN SEARCH AND ADD AFTER: while ($row = mysql_fetch_array($result)) { THIS: // Randomize the representative picture for categories with nb of images > 0 if ($row['nb_images'] > 0) { //Get the new reprentative picture of the category $get_new_representative_pic_id = ' SELECT id FROM '.IMAGES_TABLE.' WHERE storage_category_id = '.$row['id'].' ORDER BY RAND() LIMIT 0,1'; $new_representative_pic_id = pwg_query($get_new_representative_pic_id); $data_row = mysql_fetch_array($new_representative_pic_id); //Save the new representative picture category into the database $update = ' UPDATE '.CATEGORIES_TABLE.' set representative_picture_id = '.$data_row['id'].' WHERE id = '.$row['id']; $res_update= pwg_query($update); } // End of modification for randomizing the representative pictuve of the categorie
Perhaps this modification can be improved, but it works fine wor me.
Any comments are welcome ;)
Vincent
Offline
Thank you very much ! The mod is very easy to put and seems to be working very well !
Merci beaucoup ! Mod très facile à installer et qui a l'air de marcher super bien !
Offline
I have made a small improvment, so the representative picture of a category will be updated each time a sub-category AND the main category is browsed.
Tested with phpwebgallery 1.4.1.
1°) First: remove the first modification posted here, if you don't know how, just use the defaut (unmodified) ./include/category_subcats.inc.php file
2°) Then: modify the ./include/category_subcats.inc.php file as follow:
SEARCH AND ADD AFTER: if (mysql_num_rows($result) > 0) { $template->assign_block_vars('thumbnails', array()); // first line $template->assign_block_vars('thumbnails.line', array()); // current row displayed $row_number = 0; THIS CODE: // VBR Randomize the representative picture for categories with nb of images > 0 $get_all_cat = ' SELECT id, nb_images FROM '.CATEGORIES_TABLE.' WHERE id_uppercat '; $get_all_cat_res = pwg_query($get_all_cat); while ($get_all_cat_res_row = mysql_fetch_array($get_all_cat_res)) { if ($get_all_cat_res_row['nb_images'] > 0) { //Get the new reprentative picture of the category $get_new_representative_pic_id = ' SELECT id FROM '.IMAGES_TABLE.' WHERE storage_category_id = '.$get_all_cat_res_row['id'].' ORDER BY RAND() LIMIT 0,1'; $new_representative_pic_id = pwg_query($get_new_representative_pic_id); $data_row = mysql_fetch_array($new_representative_pic_id); //Save the new representative picture category into the database $update = ' UPDATE '.CATEGORIES_TABLE.' set representative_picture_id = '.$data_row['id'].' WHERE id = '.$get_all_cat_res_row['id']; $res_update= pwg_query($update); } } // VBR End of modification for randomizing the representative picture of the categorie
Now you will always have a random picture displayed for all categories/sub-categories...
Note: This modification can be a problem if your website has a lot of categories/sub-categories AND a lot of visits, due to updates made on the database
Enjoy it :)
Any comments are welcomed ;)
Offline
Yeh! A real MOD.
Comments:
Just an idea, what do you think about doing a test before the update to reduce them as much as possible (to be faster and reduce concurent update access on the db).
I don't know exactly how but saving a new representative picture should be done only time to time, do you agree?
"Guest users" and "odd seconds"
or
"Admin" and "User's name containg..."
or
"special users set with a specific option"
or
any idea
Offline
Ok ok guys, I will make a real MOD for the next release ;)
I think it could be possible to calculate the category random representative picture on the fly, each time someone is browsing a category or a sub category. By the way, no more updates onto the database ;)
I will try to do it, when I will have some time to spend on it :p
Thank you for your remarks.
Offline
Here is the version 1.0.2 of this phpwebgallery modification.
##############################################################
## Author Notes:
##
## ### English ###
##
## This MOD permits to get on the fly a random representative picture for a category or a sub category each time
## a user is browsing the main category or a sub category.
##
## If you haven't modifiy the file category_subcats.inc.php, you can just replace the
## file ./include/category_subcats.inc.php of your phpwebgallery website by the one included
## in the './Modified category_subcats.inc.php/' directory of this package.
##
## You can also find the original (unmodified) file in the directory './Original category_subcats.inc.php file/'.
##
##############################################################
## MOD History:
##
## 2005-07-24 - version 1.0.2
## - Fix to get the representative picture on the fly, no more updates onto the database :)
##
## 2005-07-23 - Version 1.0.1
## - Fix the mod to get a random representative picture also while browsing a main category
##
## 2005-07-10 - Version 1.0.0
## - Initial Release
##
##############################################################
You can get it there: http://vincent.brille.free.fr/pwg_MOD_r … icture.rar
As usual, any comments are welcomed :)
Offline
:(
le mod marche plus ! quand on va dans certaines catégories on reçoit un message comme :
SELECT path, tn_ext FROM phpwebgallery_categories AS c INNER JOIN phpwebgallery_images AS i ON i.id = ORDER BY RAND() LIMIT 0,1 ; [mysql error 1064] You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY RAND() LIMIT 0,1' at line 4
ou
SELECT path, tn_ext
FROM phpwebgallery_categories AS c INNER JOIN phpwebgallery_images AS i
ON i.id =
AND c.id NOT IN (1,215,213,21,22,25,235,234,214,159,216)
ORDER BY RAND()
LIMIT 0,1
;
[mysql error 1064] You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND c.id NOT IN (1,215,213,21,22,25,235,234,214,159,216)
ORDE
je remis le fichier category_subcats.inc.php original donc ya plus le problème... Je crois que c'est dans les catégories où il y a des sous-catégories virtuelles... Mais je sais pas trop c'est bizarre !
Offline
Hello Yann,
I've found something wrong, if a category doesn't have any image... (this could occur if you create a new directory without synchronizing images)
I've made the correction and tested also with virtual category, it seems to be ok now...
You can get the last version 1.0.3 of this MOD here: http://vincent.brille.free.fr/pwg_MOD_r … icture.rar
Can you tell me if it's ok for you now ?
Thank you :)
Offline
thank you very much ! This work very well : http://yanndinendal.free.fr/phpwebgallery
Offline
Gooood!
and nice gallery ;)
Thank you,
Vincent
Offline
Pour moi ca ne marche pas vraiment à moins que j'ai fait une mauvaise manip, mais cela va me piocher des images un peu n'importe ou pour les mettre en représentation d'une catégorie.
C'est à dire que l'image representative ne vient pas forcément de la categorie concernée!
D'autres ont ils eu ce probleme?
Salut,
Si tu as fais un mauvaise manip et si tu n'as jamais modifié le fichier category_subcats.inc.php le plus simple est de copier directement le fichier modifié contenu dans le repertoire './Modified category_subcats.inc.php/'.
La modification va chercher une image au pif contenu dans le repertoire (dans la categorie) en question.
Tiens moi au courant...
A+
Vincent
Offline
??? What are you speaking about? Here it's an English forum.
Offline