Ich habe mir das JQuery Teaser Modul als Grundlage genommen.
Die Ausgabe erfolgt in Div-Boxen, ohne den jQuery-Kram.
Ich möchte aus der ausgewählten Kategorie die eingegebene Anzahl
von Artikeln per Zufall auslesen lassen.
Wie kann ich das Modul entsprechend erweitern?
Code: Alles auswählen
<h1>Erfahrungsberichte</h1>
<div class="box">
<?php
// -- JQuery Teaser Modul --
// -- Andreas Otte --
// -- otte@otte.net --
// -- Version 1.0 -- */
if (!function_exists('truncate'))
{
function truncate($string, $length = 80, $etc = '...', $break_words = false)
{
if ($length == 0)
return '';
if (strlen($string) > $length)
{
$length -= strlen($etc);
if (!$break_words)
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length +1));
return substr($string, 0, $length).$etc;
}
else
return $string;
}
}
// Sortierfunktion by Prio
// siehe http://wiki3.redaxo.de?n=R3.Sortiermöglichkeiten
if (!function_exists('sortArticlesByPrio')) {
function sortArticlesByPrio( $artA, $artB) {
$prioA = $artA->getPriority();
$prioB = $artB->getPriority();
if ( $prioA == $prioB) {
return 0;
}
return $prioA > $prioB ? -1 : 1;
}
}
// Sortierfunktion by CreateDate
// siehe http://wiki3.redaxo.de?n=R3.Sortiermöglichkeiten
if(!function_exists('sortArticlesByCreateDate')) {
function sortArticlesByCreateDate( $artA, $artB) {
$createA = $artA->getCreateDate();
$createB = $artB->getCreateDate();
if ( $createA == $createB) {
return 0;
}
return $createA > $createB ? -1 : 1;
}
}
// Sortierfunktion by UpdateDate
// siehe http://wiki3.redaxo.de?n=R3.Sortiermöglichkeiten
if(!function_exists('sortArticlesByUpdateDate')) {
function sortArticlesByUpdateDate( $artA, $artB) {
$updateA = $artA->getUpdateDate();
$updateB = $artB->getUpdateDate();
if ( $updateA == $updateB) {
return 0;
}
return $updateA > $updateB ? -1 : 1;
}
}
// Sortierfunktion by Name
// siehe http://wiki3.redaxo.de?n=R3.Sortiermöglichkeiten
if(!function_exists('sortArticlesByName')) {
function sortArticlesByName( $artA, $artB) {
$nameA = $artA->getName();
$nameB = $artB->getName();
if ( $nameA == $nameB) {
return 0;
}
$names = array($nameA,$nameB);
sort( $names, SORT_STRING);
return $names[0] == $nameA ? -1 : 1;
}
}
$catId = 'REX_VALUE[1]';
$lettersPerArticle = 'REX_VALUE[2]';
$sorting_order = 'CreateDate';
$mediaOut = '';
$itemsPerSide = "REX_VALUE[4]"; // Anzahl der News die gezeigt werden sollen
$cat = OOCategory::getCategoryById($catId);
$childs = $cat->getArticles( true);
if ( is_array( $childs)) {
if('REX_VALUE[5]') {
usort($childs, 'sortArticlesBy'.$sorting_order);
}
$counter = 1;
foreach ( $childs as $child)
{
$id = $child->getId();
// Startartikel ausblenden
if ( $id == REX_VALUE[1]) continue;
// Den aktuellen Artikel nicht verlinken
if ($id == REX_ARTICLE_ID) continue;
$article = new article( $id);
$name = $child->getName(); // Artikel Name
$date = $child->getCreateDate(); // Erstellungs Datum
$media = $child->getFileMedia(); // Artikel Bild
$content = truncate( $article->getArticle(), 'REX_VALUE[2]'); // Anzahl Zeichen
// Ausgabe $out fuellen
if($counter <= $itemsPerSide)
{
printf ('<a href="'.$child->getUrl().'"><div class="erfahrung">%s', $content);
print '<p class="autor"><em>'.$name.'</em></p>';
print '</div></a></div>';
}
$counter++; // wiederholen bis Anzahl der srtikel erreicht ist
}
}
?>
</div>
andré