One of the things I wanted to do when integrating Gallery 2 into WordPress (using the WPG2 plugin) was to be able to see, on the main page, all the latest pictures posted in my gallery. The WPG2 plugin only supported displaying the last item added, and I could not find anyone else to have done this. So, I wrote up a quick hack to perform this function. It’s not pretty, but it does the job. Feel free to use it for your own site.
In order to display the latest items added to your gallery, paste this code in your theme where you want it to be displayed. You can specify how far you want to go back by changing $gc_item_limit.
//Find the latest Gallery pictures
$gc_item_limit = 4; //number of items to display
$gc_connection = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Can't connect to DB Server.<br />".mysql_error());
$gc_dbconnection = mysql_select_db(DB_NAME, $gc_connection) or die("Can't connect to DB.<br />".mysql_error());
$gc_run = 'SELECT g_id FROM g2_Item WHERE g_canContainChildren = 0 ORDER BY g_id DESC LIMIT '.$gc_item_limit;
$gc_result = mysql_query($gc_run);
if (mysql_num_rows($gc_result) < 1)
echo '<p>No Pictures Found< /p>';
while ($row = mysql_fetch_array($gc_result, MYSQL_ASSOC)) {
$gc_imageblock = g2_imageblock($row['g_id'], 120);
$gc_imageblock = str_replace('id="g2content"', '', $gc_imageblock);
echo $gc_imageblock;
}
mysql_free_result($gc_result);
You can see this code in action on my index page.