With GalleryEmbed::getImageBlock($args); you can include image blocks (random images, specific images, ...) in other pages of your website. It offers all the options of the external imageblock (see site admin -> image block) for embedded G2 installations and for webservers that don't allow url_fopen (and thus don't allow the readfile() method to include the external imageblock).
The GalleryEmbed::init arguments differ for every installation. The following is just an example for a case where G2 is installed in a folder called /gallery2/ under the webroot directory and where the page where we include the image block is in a file in the webroot itself.
Also, we show here a single random image. You can show multiple blocks with a single call, just use a pipe (|) delimited list of blocks in the 'blocks' => string. For example, the 3 most recent images is 'block' => 'recentImage|recentImage|recentImage'. If you copy/paste the whole getImageBlock call you'll get the same image 3 times, so make sure to use a single call with a | separated list!
<?php
/* You'll have to change the /gallery2/ thing in the following 2 lines probably */
require_once(dirname(__FILE__) . '/gallery2/embed.php');
$ret = GalleryEmbed::init(array('fullInit' => true, 'embedUri' => '/', 'g2Uri' => '/gallery2/main.php'));
if ($ret) {
print 'GalleryEmbed::init failed, here is the error message: ' . $ret->getAsHtml();
exit;
}
/*
* See "Site admin" -> "image block" for all available options. the parameters are the same
* as for the external imageblock
*/
list ($ret, $bodyHtml, $headHtml) = GalleryEmbed::getImageBlock(array('blocks' => 'randomImage',
'show' => 'title|date'));
if ($ret) {
print 'GalleryEmbed::getImageBlock failed, here is the error message: ' . $ret->getAsHtml();
exit;
}
/* $bodyHtml contains the image block. print it somewhere on your website */
print $bodyHtml;
/*
* $headHtml is not required. if you use imageframes for your imageblocks, you need to print
* $headHtml in the <head> section of your web page
*/
?>
The code above displays a random image.
You can also display a specific image. Simply replace randomImage with specificItem, and define it's ID with itemId, like this:
list ($ret, $bodyHtml, $headHtml) = GalleryEmbed::getImageBlock(
array('blocks' => 'specificItem', 'itemId' => 25, 'show' => 'title|date'));
If you know the path of the item but not the ID, you can find the ID like this:
list ($ret, $itemId) = GalleryCoreApi::fetchItemIdByPath('albumName/imageName.jpg');
if ($itemId) {
list ($ret, $bodyHtml, $headHtml) = GalleryEmbed::getImageBlock(
array('blocks' => 'specificItem', 'itemId' => $retrievedItemID[1], 'show' => 'title|date'));
Add CSS like this to your page to get the blocks to display horizontally:
.one-image { float: left; }
a img { border: 0; }