Hello/Hi/Greetings,
I try to use piwigo for giving users the ability to rate photos from my gallery to make a "best of". Is there a quick way to vote for a picture (e.g. pressing 0-5 on the keyboard)?
I only found this older thread but it did not provide a solution (https://piwigo.org/forum/viewtopic.php?id=28015).
Piwigo 15.5.0 Prüfen, ob eine neue Version verfügbar ist.
Installiert auf 27 April 2025, vor 15 Stunden
Betriebssystem: Linux
PHP: 8.3.15 (Info anzeigen) [2025-04-27 22:00:37]
MySQL: 11.4.5-MariaDB-log [2025-04-27 22:00:37]
Grafikbibliothek: GD bundled (2.1.0 compatible)
Größe des Cache 505.06 Mo berechnet vor 7 Stunden Aktualisieren
Piwigo URL: http://
Offline
Currently, Piwigo doesn't offer an out-of-the-box feature for using keyboard shortcuts (such as pressing 0-5 to rate a picture). However, it's possible to add this functionality through custom JavaScript or modifications to your Piwigo theme.
Here's a rough outline of how you might add keyboard shortcuts to allow users to rate images from 0 to 5:
Add custom JavaScript: You can inject custom JavaScript into your Piwigo gallery to detect keypresses and trigger the rating system. This would involve adding a script to your theme’s template files or using the plugin system if you’re comfortable with that.
Sample JavaScript code: Here's a basic script that listens for keypresses (0-5) and simulates rating a picture. It assumes that each picture has a data-id attribute and that the rating system is tied to these IDs.
javascript
Kopyala
Düzenle
document.addEventListener('keydown', function(event) {
if (event.key >= '0' && event.key <= '5') {
let rating = event.key; // Rating from 0 to 5
let imageId = document.querySelector('.piwigo-photo').dataset.id; // Assume there's a class 'piwigo-photo'
// Simulate the action of rating the image. You'll need to replace this with the actual Piwigo function to submit the rating.
// Example: submitRating(imageId, rating);
console.log(`Rating image ${imageId} with a score of ${rating}`);
// You could also trigger a click event on the corresponding rating button here.
}
});
This is just a simple script that detects when the user presses any key between 0 and 5 and logs it.
To make this work in Piwigo, you’ll need to modify the code to call Piwigo's internal functions to rate the image (or trigger a form submission).
Adding the script:
You could inject the above script into your theme's head.tpl file or in a plugin that allows you to add custom JS.
Make sure to test the script on a staging site first to ensure it doesn’t conflict with existing functionality.
Custom plugin: If you're familiar with PHP, you could also write a small plugin to handle this. The plugin would listen for the keypress events and interact with Piwigo's backend to submit the rating.
Since this isn’t a built-in feature of Piwigo, there’s some custom work involved. Would you like more details on how to implement this? Or if you prefer, I can help you find a plugin or extension that might make it easier!
Offline