ich habe versucht, das Modul "05 - Kategorienliste" zu verwenden. Leider funktioniert das weder mit Textile- noch mit Fließtext (tinyMCE)-Artikeln, wenn man die Anzahl der Wörter einschränkt. Das Problem ist, dass diese Artikel mit </p></div> abgeschlossen werden, was inkorrekt eingefügt wird, wenn nicht alle Wörter das Artikels angezeigt werden sollen. Dadurch wird ungültiger html-Code erzeugt.
Ich habe den Code der Ausgabe modifiziert, sodass er jetzt funktioniert:
Code: Alles auswählen
<?php
$cat = OOCategory :: getCategoryById($this->getValue('category_id'));
$cats = $cat->getChildren();
$itemsPerSide = "REX_VALUE[1]";
$wordsPerArticle = "REX_VALUE[2]";
if (is_array($cats))
{
$i = 0;
foreach ($cats as $cat)
{
$i += 1;
if ($i <= $itemsPerSide)
{
if ($cat->isOnline())
{
$catId = $cat->getId();
$catName = $cat->getName();
$article = $cat->getArticles();
if (is_array($article))
{
foreach ($article as $var)
{
$articleId = $var->getId();
$articleName = $var->getName();
$art = new rex_article($articleId);
$articleContent = $art->getArticle();
$articleContent = trim($articleContent);
// Ensure that any on these tags are in seperate words in the array by adding a space
$articleContent = str_replace('</p>', ' </p>', $articleContent);
$articleContent = str_replace('<br />', ' <br />', $articleContent);
$articleContent = str_replace('</div>', ' </div>', $articleContent);
$output = '';
$words = explode(' ', $articleContent);
$wordsCount = count($words);
// Find the last real word before any html end character. After this, only end tags like </p> and </div>
// are found. They have to be added to the resulting string after the number of words is reduced.
for ($i=$wordsCount-1; $i>0; --$i)
{
// Find any ending html tag (e.g. </div>), or spaces or empty words
if (preg_match("{</(.*?)>|\s|^$}", $words[$i])==1)
{
--$wordsCount;
}
else
{
break;
}
}
if ($wordsCount < $wordsPerArticle)
$wEnd = $wordsCount;
else
$wEnd = $wordsPerArticle;
for ($w = 0; $w < $wEnd; $w++)
{
$output .= $words[$w] . ' ';
}
// Output "more" in the used languages, in this case is 0 German and 1 is Dutch.
$clang = rex_get('clang', 'int', REX_CLANG_ID);
if ($clang == 0)
{
$more = "Mehr";
}
else
{
$more = "Meer";
}
$output .= '<a href="' . rex_getUrl($articleId) . '" class="more"> ...'.$more.'</a>';
// Add finishing thml tags, which were cut off previously.
$no_ending_words = count($words) - $wordsCount;
for ($i = 0; $i < $no_ending_words; ++$i)
{
$output .= $words[$wordsCount + $i]." ";
}
print '<div class="txt-img">' . $output . '</div>';
}
}
}
}
}
}
?>