Alle Artikel einer Kategorie ausgeben.

Wie verwendet man Module oder Aktion und passt diese an.

Alle Artikel einer Kategorie ausgeben.

Beitragvon f0rza » 30. Jun 2008, 13:59

Hallo,
ich habe folgendes Problem.

Ich würde gerne alle Artikel einer Kategorie untereinander im Startartikel ausgeben. Am besten 2-spaltig und alphabetisch nach Artikelnamen sortiert.

Ich habe da jetzt schon einiges probiert und auch im Forum gesucht. Jedoch bin ich auf keine Lösung gekommen.

Kann jemand helfen?
f0rza
 
Beiträge: 21
Registriert: 1. Feb 2007, 18:31

Beitragvon Markus.Staab » 30. Jun 2008, 15:50

Hi f0rza,

schau mal hier, da gibts ca 30 Varianten:
http://www.redaxo.de/17-0-modulsuche.ht ... searchtxt=

Gruß,
Markus
Benutzeravatar
Markus.Staab
Entwickler
 
Beiträge: 9781
Registriert: 29. Jan 2005, 14:50
Wohnort: Aschaffenburg/Germany

Beitragvon f0rza » 30. Jun 2008, 16:11

Danke. Die meisten hab ich glaube ich schon probiert. :?

Mein Problem ist folgendes:
Ich möchte in der Kategorie "NEWS" im Startartikel alle Artikel dieser Kategorie anteasern. Dafür verwende ich folgendes Modul:

Ausgabe
Code: Alles auswählen
<?php
$itemsPerSide = "REX_VALUE[1]";
$wordsPerArticle = "REX_VALUE[2]";
$articles = "REX_VALUE[3]";

if (!$REX['REDAXO']) {

// Sortierfunktion
if(!function_exists("sortArticlesByREX_VALUE[4]REX_VALUE[5]")) {
  function sortArticlesByREX_VALUE[4]REX_VALUE[5]( $artA, $artB) {
    $sortby = 'REX_VALUE[4]';

    $createA = $artA->getValue($sortby);
    $createB = $artB->getValue($sortby);

    if ( $createA == $createB) {
      return 0;
    }

    if('REX_VALUE[5]') return $createA > $createB ? -1 : 1;
    else  return $createA < $createB ? -1 : 1;
  }
}

$start = !empty($_GET['start']) ? (int) $_GET['start'] : 0; // Startitem
$offset = $itemsPerSide; // 10 Items pro Seite
$cats = array( $articles); // alle Kategorien die Du "indizieren" willst

$articles = array();

foreach ( $cats as $catId) {
  $cat = OOCategory::getCategoryById( $catId);

  // CatIds die nicht funktionieren aussortieren
  if( $cat === null) {
     continue;
  }

  $cat_articles = $cat->getArticles( true);

  foreach ( $cat_articles as $ooarticle) {
     // keine Startartikel anzeigen
    if ( $ooarticle->isStartPage()) {
       continue;
     }

     // Damit keine Endlosschleife passiert, den Artikel der die Pagination setzt ¸berspringen
     if ( $ooarticle->getId() == REX_ARTICLE_ID) {
        continue;
     }
     $articles[] = $ooarticle;
  }
}

$articles_length = count( $articles);

// Sortieren
if ( $articles_length > 0) {
  usort( $articles, "sortArticlesByREX_VALUE[4]REX_VALUE[5]");
}

$article_list = array_slice( $articles, $start, $offset);

foreach ( $article_list as $ooarticle) {
  if ($ooarticle->isOnline(true)) {
    $articleId = $ooarticle->getId();
    $article = new article();
    $article->setArticleId( $articleId);
    $articleContent = $article->getArticle();

    // Leerzeichen entfernen am Anfang und Ende des Strings
    $articleContent = trim($articleContent);

    // Leerzeichen vor </p> einfuegen.
    // Sonst wird das letzte Wort eines Absatzes und das erste Wort
    // des nachfolgenden Absatzes als ein Wort erkannt
    $articleContent = str_replace("</p>", " </p>", $articleContent);
      
    // Leerzeichen vor <br /> einfuegen.
    // Sonst wird das letzte Wort einer Zeile und das erste Wort
    // des nachfolgenden Zeile als ein Wort erkannt
    $articleContent = str_replace("<br />", " <br />", $articleContent);

    $output = "";
    $words = explode(" ",$articleContent);
    $wordsCount = count($words);
    //$wordsCount = str_word_count($articleContent);

    if ($wordsCount < $wordsPerArticle) $wEnd = $wordsCount;
    else  $wEnd = $wordsPerArticle;
    for ($w=0;$w<$wEnd;$w++) {
      $output .= $words[$w]." ";
    }

    // Leerzeichen entfernen am Anfang und Ende des Strings   
    $output = trim($output);
    $isCloseParagraph = substr($output,-4);

    // opened & closed TDs/TRs/TABLEs zählen und ggf. closing Tags ergänzen
    $openedTDs = substr_count($output, '<td');
    $closedTDs = substr_count($output, '</td>');
    $countmissingTDs = $openedTDs - $closedTDs;
     
    if ($openedTDs > $closedTDs) {
      while ($countmissingTDs > 0):
        $output .= "</td>";
        $countmissingTDs = $countmissingTDs - 1;
      endwhile;
    }

    $openedTRs = substr_count($output, '<tr');
    $closedTRs = substr_count($output, '</tr>');
    $countmissingTRs = $openedTRs - $closedTRs;
     
    if ($openedTRs > $closedTRs) {
      while ($countmissingTRs > 0):
        $output .= "</tr>";
        $countmissingTRs = $countmissingTRs - 1;
      endwhile;
    }

    $openedTABLEs = substr_count($output, '<table');
    $closedTABLEs = substr_count($output, '</table>');
    $countmissingTABLEs = $openedTABLEs - $closedTABLEs;
     
    if ($openedTABLEs > $closedTABLEs) {
      while ($countmissingTABLEs > 0):
        $output .= "</table>";
        $countmissingTABLEs = $countmissingTABLEs - 1;
      endwhile;
    }

    $link = ' <a href="'.rex_getUrl($articleId).'">...mehr &raquo;</a>';
    $newString = $link.'</p>';

    if ($isCloseParagraph == '</p>') {
      $output = substr_replace($output,$newString,-4);
    }
    else {
      $output .= $newString;
    }

    // opened & closed DIVs/SPANs zählen und ggf. closing Tags ergänzen
    $openedSPANs = substr_count($output, '<span');
    $closedSPANs = substr_count($output, '</span>');
    $countmissingSPANs = $openedSPANs - $closedSPANs;
     
    if ($openedSPANs > $closedSPANs) {
      while ($countmissingSPANs > 0):
        $output .= "</span>";
        $countmissingSPANs = $countmissingSPANs - 1;
      endwhile;
    }

    $openedDIVs = substr_count($output, '<div');
    $closedDIVs = substr_count($output, '</div>');
    $countmissingDIVs = $openedDIVs - $closedDIVs;
     
    if ($openedDIVs > $closedDIVs) {
      while ($countmissingDIVs > 0):
        $output .= "</div>";
        $countmissingDIVs = $countmissingDIVs - 1;
      endwhile;
    }

    print '<div>'.$output.'</div>';
  }
}

$prevStart = $start - $offset;
if ( $prevStart < 0)
{
   $prevStart = '';
}

$nextStart = $start + $offset;
if ( $nextStart >= $articles_length)
{
   $nextStart = '';
}

$link_format = '<a href="index.php?article_id=REX_ARTICLE_ID&start=%s">%s</a>';

// Vorherige Seite Link
if ( $prevStart !== '') {
  $backLink = sprintf( $link_format, $prevStart, '&laquo; vorherige Seite');
}

// Nächste Seite Link
if ( $nextStart !== '') {
  $nextLink = sprintf( $link_format, $nextStart, 'n&auml;chste Seite &raquo;');
}

if ($backLink != "" AND $nextLink != "") {
  print '<div>'.$backLink.'&nbsp;|&nbsp;'.$nextLink.'</div>';
}
elseif ($nextLink != "") {
  print '<div>'.$nextLink.'</div>';
}
elseif ($backLink != "") {
  print '<div>'.$backLink.'</div>';
}
}
else {
  echo "Anzahl der News pro Seite: REX_VALUE[1]<br />Anzahl der Wörter pro Newsartikel: REX_VALUE[2]<br />Kategorie: REX_VALUE[3]";
}

?>


Leider werden mir aber alle Spalten ausgegeben. Ich möchte aber lediglich die Content-Spalte anzeigen lassen.
f0rza
 
Beiträge: 21
Registriert: 1. Feb 2007, 18:31

Beitragvon Markus.Staab » 30. Jun 2008, 16:23

Hi,

was ist in deinen Augen eine Content-Spalte?

Gruß,
Markus
Benutzeravatar
Markus.Staab
Entwickler
 
Beiträge: 9781
Registriert: 29. Jan 2005, 14:50
Wohnort: Aschaffenburg/Germany

Beitragvon f0rza » 30. Jun 2008, 17:19

naja. ich habe in meinem template 3 spalten (ctypes).
eine davon ist eben die "content"-spalte mi der ID 1.
f0rza
 
Beiträge: 21
Registriert: 1. Feb 2007, 18:31

Beitragvon Markus.Staab » 30. Jun 2008, 17:49

Hi,

dann musst du in deinem Modul, beim Aufruf von getArticle() den Ctype mit angeben..

Gruß,
Markus
Benutzeravatar
Markus.Staab
Entwickler
 
Beiträge: 9781
Registriert: 29. Jan 2005, 14:50
Wohnort: Aschaffenburg/Germany

Beitragvon f0rza » 1. Jul 2008, 07:58

Aha. Danke.

geht das dann also mit ...
Code: Alles auswählen
$article->getArticle(CTYPE_ID);
...?

lg forza
f0rza
 
Beiträge: 21
Registriert: 1. Feb 2007, 18:31

Beitragvon Markus.Staab » 1. Jul 2008, 10:28

Hi f0rza,

jepp, das ist genauso wie wenn du im Template getArticle(CTYPE_ID) schreibst..

Gruß,
Markus
Benutzeravatar
Markus.Staab
Entwickler
 
Beiträge: 9781
Registriert: 29. Jan 2005, 14:50
Wohnort: Aschaffenburg/Germany

Beitragvon f0rza » 1. Jul 2008, 10:30

Super. Danke.

lg f0rza
f0rza
 
Beiträge: 21
Registriert: 1. Feb 2007, 18:31


Zurück zu Module/Aktionen [R4]

Wer ist online?

Mitglieder in diesem Forum: Google [Bot] und 1 Gast