hat jemand einen tipp / modul / codeschnippsel wie ich eine anzahl (x) bilder aus einer medienkategorie inkl. unterkategorien zufällig anzeigen lassen kann.
die module im downloadbereich sind nur für [R3] (und arbeiten anscheinend nicht mit image resize (?).
z.B. dieses modul von Katharina Hirsch [Web & Breakfast]:
eingabe
Code: Alles auswählen
<?php
///////////////////////////////////////////
function MediaCats( $cat = null) {
$selectCats = null;
if ( is_int( $cat)) {
$selectCats = array( OOMediaCategory::getCategoryById( $cat));
} else if ( OOMediaCategory::isValid( $cat)) {
$selectCats = array( $cat);
} else {
$selectCats = OOMediaCategory::getRootCategories();
}
foreach ( $selectCats as $selectCat) {
add_cat_option( $selectCat);
}
}
function add_cat_option( &$cat, $groupName = '') {
if( empty( $cat)) {
return;
}
print_link($cat->getName(), $cat->getId(), $groupName);
if ( $cat->hasChildren()) {
$childs = $cat->getChildren();
foreach ( $childs as $child) {
if ($child->hasChildren()) {
add_cat_option( $child, $cat->getName());
} else {
add_cat_option( $child, $cat->getName());
}
}
}
}
function print_link($catName, $catId, $groupName) {
global $selectedCat;
if ( "REX_VALUE[1]" == $catId) {
// selected
echo "<option value=\"" . $catId . "\" selected>" . $catName . "</option>\n";
} else {
echo "<option value=\"" . $catId . "\">" . $catName . "</option>\n";
}
}
///////////////////////////////////////////////////////
echo "<h2>Zufalls Bild</h2>";
echo "Bitte wählen Sie eine Kategorie:<br />\n";
// show the mediapool-categories
echo "\n<select class=\"inp50\" name=\"VALUE[1]\">\n";
MediaCats();
echo "</select>\n";
echo "<br /><br />";
?>
Code: Alles auswählen
<?php
$bild[0] ="";
$bild = array();
$result[0] ="";
$result = array();
$mediacat = REX_VALUE[1];
$cat = OOMediaCategory::getCategoryById($mediacat);
if ($cat->hasChildren()) {
$childs = $cat->getChildren();
foreach($childs as $child) {
$idCategory = $child->getId();
$cat2 = OOMediaCategory::getCategoryById($idCategory);
$bild = array_merge($result,$bild);
}
}
shuffle($bild);
$randIndex = mt_rand( 0, count( $bild) -1);
$bild2 = $bild[ $randIndex];
$fileName = $bild2->getFileName();
$title = $bild2->getTitle();
echo "<div class='portlet'><h3>Aus der Galerie</h3>";
echo "<p id='shuffle'><img src='{$REX['HTDOCS_PATH']}index.php?rex_resize=110h__$fileName' alt='$title' /><br />$title</p></div>";
?>