eigentlich findet sich fast immer eine Antwort im Forum. Heute muss ich mal eine Frage beisteuern:
Ich habe in einer Redaxo 4.1 Installation eine Artikelliste mit Sortierung gebastelt, die aber nur funktioniert, wenn der Artikel mit der Liste im Home-Verzeichnis liegt?!
Grundlage ist das multilist-Modul von Dennis Wenger. Dazu habe ich einen Code-Snipsel aus dem Forum, dass nach einem Value[1] des ersten Moduls (hier liegt ein Datum) sortiert wird.
Das Modul funktioniert prima, wenn ich im Home-Verzeichnis bin. Sobald ich in einer Kategorie bin, wird nicht sortiert.
Danke für Hilfe und Grüße
Ruben
... und hier der Ausgabe-Code:
Code: Alles auswählen
<?php
//### Functions ###
// Filtern
if(!function_exists("filterArticles")){
function filterArticles($artarr, $withstartpage='0', $onlyteaser='0', $metatime='0'){
$show_articles = array();
foreach ($artarr as $thearticle){
if(REX_ARTICLE_ID != $thearticle->getValue('id')){ //Selbstauflistung unterbinden
//Startartikel
if($withstartpage == '1' || $thearticle->getValue('startpage') != '1'){
//Teaser
if(($onlyteaser != '1' && $onlyteaser != '3') || $thearticle->getValue('teaser') == '1'){
//Datum: online_from / online_to
if($metatime != '1' || ($thearticle->getValue('online_from') <= date('U') && $thearticle->getValue('online_to') >= date('U'))){
$show_articles[] = $thearticle;
}
}
}
}
}
return $show_articles;
}
}
// Sortierfunktion
if(!function_exists("nachDatumsortierenREX_VALUE[6]")){
function nachDatumsortierenREX_VALUE[6]( $artA, $artB) {
$sliceArtA = OOArticleSlice::getFirstSliceForArticle( $artA->getId() );
$sliceArtB = OOArticleSlice::getFirstSliceForArticle( $artB->getId() );
// REX_VALUE[1] abfragen
$updateA = $sliceArtA->getValue(1);
$updateB = $sliceArtB->getValue(1);
$updateA = ereg_replace("\.","",$updateA);
$Tag = substr($updateA,0, -6);
$Monat = substr($updateA,2, -4);
$Jahr = substr($updateA,4, 4);
$updateA = $Jahr.$Monat.$Tag;
$updateB = ereg_replace("\.","",$updateB);
$Tag = substr($updateB,0, -6);
$Monat = substr($updateB,2, -4);
$Jahr = substr($updateB,4, 4);
$updateB = $Jahr.$Monat.$Tag;
// Werte vergleichen
if($updateA == $updateB)
return 0;
if('REX_VALUE[6]') return $updateA > $updateB ? -1 : 1;
else return $updateA < $updateB ? -1 : 1;
}
}
if(!function_exists("generatePagination")){
function generatePagination($articles, $listpage='0', $itemsperpage, $listnum){
$GETPARAMS = $_GET;
unset($GETPARAMS['list'.$listnum.'page']);
if($itemsperpage > 0){
$prevtext = "←";
$nexttext = "→";
$itemcount = count($articles);
$output = '';
$pagecount = ceil($itemcount / $itemsperpage);
if($pagecount > 1){
if($listpage > $pagecount) $listpage = $pagecount;
$prevpagenum = -1;
$nextpagenum = -1;
if($listpage > 0) $prevpagenum = $listpage-1;
if($listpage < ($pagecount-1)) $nextpagenum = $listpage+1;
$output = '<div id="pagination">';
if($prevpagenum >= 0) $output .= '<a href="'.rex_getUrl(REX_ARTICLE_ID).'?list'.$listnum.'page='.$prevpagenum.'&'.http_build_query($GETPARAMS).'" id="prevlink">'.$prevtext.'</a> ';
for($pagenum = 0; $pagenum < $pagecount; $pagenum++){
if($pagenum == $listpage){
$output .= '<b>'.($pagenum+1).'</b> ';
}
else{
$output .= '<a href="'.rex_getUrl(REX_ARTICLE_ID).'?list'.$listnum.'page='.$pagenum.'&'.http_build_query($GETPARAMS).'">'.($pagenum+1).'</a> ';
}
}
if($nextpagenum > 0) $output .= '<a href="'.rex_getUrl(REX_ARTICLE_ID).'?list'.$listnum.'page='.$nextpagenum.'&'.http_build_query($GETPARAMS).'" id="nextlink">'.$nexttext.'</a>';
$output .= '</div>';
}
return $output;
}
else{
return "";
}
}
}
if(!function_exists("limitArticles")){
function limitArticles($articles, $listpage = '0', $itemsperpage){
if($itemsperpage){
$itemcount = count($articles);
$pagecount = ($itemcount / $itemsperpage);
if($listpage > $pagecount) $listpage = $pagecount;
$offset = $listpage*$itemsperpage;
return array_slice ($articles, $offset ,$itemsperpage);
}
return $articles;
}
}
if(!function_exists("createArticleOutput")){
function createArticleOutput($article, $thumbsize, $fromMetadata, $withmorelink){
global $REX;
$articleId = $article->getId();
if($fromMetadata != '1'){ // from Metadata
$headline = $article->getValue('name');
$newstext = $article->getValue('description');
$image = $article->getValue('file');
}
else{ // from first Slice
if($firstSlice = OOArticleSlice::getFirstSliceForArticle($articleId)){
$headline = $firstSlice->getValue(3);
$newstext = $firstSlice->getValue(1);
if ($firstSlice->getValue(2) != "") {
$newstext .= ' – '.$firstSlice->getValue(2);
}
$image = $firstSlice->getFile(1);
}
}
$output .= '<div>';
if($thumbsize != '0'){
$output .= '<div class="newsimage">';
if($image != ''){
$output .= '<a href="'.rex_getUrl($articleId).'"><img src="'.$REX[HTDOCS_PATH].'index.php?rex_resize='.$thumbsize.'a__'.$image.'"></a>';
}
$output .= '</div>';
}
$output .= '<div class="newstext"><b>'.$headline.$updateA.'</b><br>';
$output .= $newstext;
if($withmorelink<2) $output .= '<br><a class="more" title="Den gesamten Text anzeigen" href="'.rex_getUrl($articleId).'">» anzeigen</a>';
$output .= '</p></div></div>';
return $output;
}
}
// Ausgabe-Code erzeugen
//nummerierung für GET
if($MLnum <0) $MLnum = 1;
else $MLnum ++;
$articles = OOArticle::getArticlesOfCategory('REX_VALUE[1]', true);
if (is_array($articles))
{
//Filtern
$articles = filterArticles($articles, 'REX_VALUE[2]', 'REX_VALUE[3]', 'REX_VALUE[4]');
}
if (count($articles) > 0)
{ //sortieren
if('REX_VALUE[5]'){
usort($articles, 'nachDatumsortierenREX_VALUE[6]');
}
//generate Pagination
$pagination = "";
if('REX_VALUE[9]' > 0){
$listpage = !empty($_GET['list'.$MLnum.'page']) ? (int) $_GET['list'.$MLnum.'page'] : 0;
if('REX_VALUE[10]' == '1'){
$pagination = generatePagination($articles, $listpage, 'REX_VALUE[9]', $MLnum);
}
//Limit
$articles = limitArticles($articles, $listpage, 'REX_VALUE[9]');
}
if(count($articles) > 0){
$output = '<div class="newslist">';
foreach ($articles as $var)
{
$output .= createArticleOutput($var, REX_VALUE[8], 'REX_VALUE[7]', 'REX_VALUE[3]');
}
$output .= '</div>';
echo $output.'<br>'.$pagination;
}
}
?>