2020-05-13, 21:24:23
I stopped writing ItemManager code in my website page template files.
Instead I am writing ItemManager code as a php function()
in the functions.php file
Like I did for this Gallery:
Now, with a simple <?php photobox(); ?> in a page template file I can make this Gallery popup
anywhere I want - this is great
Also this way contributes to better separation of code and html layout
Instead I am writing ItemManager code as a php function()
in the functions.php file
Like I did for this Gallery:
Code:
function photobox() {
if (return_page_slug()=='basic') {
$imanager = imanager();
$itemMapper = $imanager->getItemMapper();
// Loading the photobox-category
$itemMapper->init(8); // Category 8 is the photobox-category and holds the items photobox-images and photobox-scripts
$items = $itemMapper->items;
$photobox_scripts = $itemMapper->getItem('name=photobox-scripts');
$photobox_images = $itemMapper->getItem('name=photobox-images');
// output the css for the photobox gallery
echo '<link href="' . IM_SITE_URL.($photobox_scripts->fields->files->fullurl[0]) . '" rel="stylesheet">' . "\n"; // photobox.css
echo '<link href="' . IM_SITE_URL.($photobox_scripts->fields->files->fullurl[1]) . '" rel="stylesheet">' . "\n"; // style.css for the thumbs
// set container <div> with id="gallery" class="box-thumb" before starting the foreach loop
echo '<div id="gallery" class="box-thumb">' . "\n";
// Looping through item $photobox_images with [$key] as automatic array counter;
foreach ($photobox_images->fields->files->fullurl as $key => $fullurl) {
$url = IM_SITE_URL.$fullurl;
$title = $photobox_images->fields->files->title[$key];
// output the html for the photobox gallery
echo '<a href="' . $url . '"><img src="' . $url . '" width="100" title="' . $title . '"></a>' . "\n";
}
// set closing container </div> after the foreach loop
echo '</div>' . "\n";
// output the necessary javascript for the photobox gallery
echo '<script src="' . IM_SITE_URL.($photobox_scripts->fields->files->fullurl[2]) . '"></script>' . "\n"; // jquery-1.7.min.js
echo '<script src="' . IM_SITE_URL.($photobox_scripts->fields->files->fullurl[3]) . '"></script>' . "\n"; // jquery.photobox.js
echo '<script src="' . IM_SITE_URL.($photobox_scripts->fields->files->fullurl[4]) . '"></script>' . "\n"; // parameters.js
}
}
Now, with a simple <?php photobox(); ?> in a page template file I can make this Gallery popup
anywhere I want - this is great

Also this way contributes to better separation of code and html layout