[phpBB Debug] PHP Warning: in file [ROOT]/ext/tas2580/seourls/event/listener.php on line 213: Undefined array key "FORUM_NAME"
REDAXO Forum • [gelöst] Artikelliste mit Teaser
Seite 1 von 1

[gelöst] Artikelliste mit Teaser

Verfasst: 4. Apr 2016, 11:59
von Fanello
Liebe Redaxo-Gemeinde

Ich würde gerne in Redaxo 5 einer Artikelliste der Aktuellen Kategorie ausgeben. Dabei soll jeweils von jedem Artikel (ausser Startartikel und muss online sein) der Artikel-Name und die Beschreibung ausggeben werden. Ich starte jetzt mal mit der Ausgabe der Beschreibung, allerdings habe ich nur Teil-Erfolge zu verbuchen.
Im Moment sind zwei Artikel in der Kategorie, inkl. Startartikel.
Es wird mir auch 2x die Description ausgegeben, jedoch nur die des Startartikels (hier wird die Artikelliste eingebaut). Mir ist klar, dass es mit dem $this-> zu tun haben muss, was sich immer auf die aktuelle Kategorie bezieht. Mir ist allerdings nicht klar, wie ich die Metas aus den vorhandenen Artikeln holen kann.

Code: Alles auswählen

<?php 
$Articles = rex_category::getCurrent()->getArticles();
$CurrentArticle = rex_article::getCurrent();

foreach($Articles as $Article) {
  $description = $this->getValue('description');;
  echo $description;
}
?>
Hat jemand eine Idee?

Re: Artikelliste mit Teaser

Verfasst: 4. Apr 2016, 12:58
von Thomas.Blum
Hej,

Code: Alles auswählen

<?php 
$articles = rex_category::getCurrent()->getArticles();
if (count($articles)) {
    foreach ($articles as $article) {
        if ($article instanceof rex_article && !$article->isStartArticle()) {
            echo $article->getValue('art_description');
        }
    }
}
vg Thomas

Re: Artikelliste mit Teaser

Verfasst: 4. Apr 2016, 13:49
von Fanello
super, vielen Dank!

Re: [gelöst] Artikelliste mit Teaser

Verfasst: 9. Jun 2016, 16:03
von mmh
Hallo zusammen,
ich wollte gerade den etwas aufgebohrten Code anbieten, jetzt bin ich doch noch über ein Problem gestolpert. Offline Artikel werden auch berücksichtigt, kann mir jemand helfen diese rauszuwerfen?

Ansonsten ist der Code so aufgebohrt, dass ein Startartikel gewählt werden kann (alle Artikel dieser Kategorie werden berücksichtigt). Außerdem kann die Anahl der anzuzeigenden Artikel gewählt werden und die Reihenfolge ist umgekhrt, also die neuesten zuerst. Hat ein bisschen was von einem Blog.

Wäre schön wenn mir noch jemand beim Online/Ofline Problem helfen könnte ....

Code: Alles auswählen

    <?php
	if ('REX_VALUE[id=1 isset=1]') {
	    $number = REX_VALUE[1];
	} else {
		$number = 10;
	}
	$art_id = REX_LINK[1];
	$cat = rex_category::get($art_id);
	$articles = $cat->getArticles();
	$articles_reverse = array_reverse($articles);
	$i=0;
	foreach ($articles_reverse as $article) {
		if ($i <= $number) {		
			if ($article instanceof rex_article && !$article->isStartArticle()) {
				$headline = $article->getValue('name');
				$byline = $article->getValue('byline');
				$text = $article->getValue("teaser");				
				$img = $article->getValue("img");				
				
				echo '
					<div class="c12 item">
					<div class="c6">';

				if($img =="") {}
				else {
					echo '<img src="index.php?rex_media_type=c6&rex_media_file='.$img.'" />';
				}
				
				echo '	
					</div>
					<div class="c6">
						<h2>
							'.$headline.'
						<br><span class="byline">'.$byline.'</span>
						</h2>
						<hr class="line left" />
						<p>'.$text.'</p>
					</div>
				</div>';
            }
            
			$i++;
        }
	}
?>
Danke
Marco

Re: [gelöst] Artikelliste mit Teaser

Verfasst: 9. Jun 2016, 21:16
von Oliver.Kreischer
Hallo,

so bekommst du den Status:

Code: Alles auswählen

 $article->getValue('status'); 
LG
Oliver

Re: [gelöst] Artikelliste mit Teaser

Verfasst: 10. Jun 2016, 09:26
von mmh
Hallo Oliver,
danke für die Info,
das hatte ich irgendwo im Handbuch gefunden, leider weiß ich nicht so genau, wo und wie ich das ganze integrieren soll ;-(

Re: [gelöst] Artikelliste mit Teaser

Verfasst: 10. Jun 2016, 09:51
von runstop64
Ich würde als erste Zeile der Schleife setzen:

Code: Alles auswählen

if ($article->getValue('status') == 0) continue;

Re: [gelöst] Artikelliste mit Teaser

Verfasst: 10. Jun 2016, 10:00
von mmh
Super, danke dir!

Hier der ganze Code falls jemand was ähnliches benötigt. (Blog Vorschau von x Artikeln einer Kateogrie mit Redaxo 5)

Code: Alles auswählen

    <?php
	// Maximale Anzahl der Artikel definieren
	if ('REX_VALUE[id=1 isset=1]') {
	    $number = REX_VALUE[1];
	} else {
		$number = 10;
	}
	// Startartikel (legt Kateogrie fest)
	$art_id = REX_LINK[1];
	// Kategorie anhand von Startartikel auswählen
	$cat = rex_category::get($art_id);
	// Alle Artikel der Kateogrie	
	$articles = $cat->getArticles();
	// Reihenfolge umkehren (neuste zuerst
	$articles_reverse = array_reverse($articles);
	// Zähler Reset
	$i=0;
	// Array auslesen
	foreach ($articles_reverse as $article) {
		// Nur Artikel die Online sind einbinden
	    if ($article->getValue('status') == 0) continue;		
		// Maximale Anzahl der Artikel
		if ($i <= $number) {
			// MetaInfos auslesen
			if ($article instanceof rex_article && !$article->isStartArticle()) {
				$headline = $article->getValue('name');
				$byline = $article->getValue('byline');
				$text = $article->getValue("teaser");				
				$img = $article->getValue("img");				
				// Ausgabe
				echo '
					<div class="c12 item">
					<div class="c6">';
				if($img != '') {
					echo '<img src="index.php?rex_media_type=c6&rex_media_file='.$img.'" />';
				}
				echo '	
					</div>
					<div class="c6">
						<h2>
							'.$headline.'
						<br><span class="byline">'.$byline.'</span>
						</h2>
						<hr class="line left" />
						<p>'.$text.'</p>
					</div>
				</div>';
            }
			// Zähler +1
			$i++;
        }
	}
?>

Re: [gelöst] Artikelliste mit Teaser

Verfasst: 16. Sep 2016, 07:03
von Manuel.Schmöllerl
Danke für den Code, den konnte ich gerade gut brauchen ;-)
Ich habe Ihn noch mit einem Link auf den Detailartikel selbst erweitert.

Code: Alles auswählen

   <?php
   // Maximale Anzahl der Artikel definieren
   if ('REX_VALUE[id=1 isset=1]') {
       $number = REX_VALUE[1];
   } else {
      $number = 10;
   }
   // Startartikel (legt Kateogrie fest)
   $art_id = REX_LINK[1];
   // Kategorie anhand von Startartikel auswählen
   $cat = rex_category::get($art_id);
   // Alle Artikel der Kateogrie   
   $articles = $cat->getArticles();
   // Reihenfolge umkehren (neuste zuerst
   $articles_reverse = array_reverse($articles);
   // Zähler Reset
   $i=0;
   // Array auslesen
   foreach ($articles_reverse as $article) {
      // Nur Artikel die Online sind einbinden
       if ($article->getValue('status') == 0) continue;      
      // Maximale Anzahl der Artikel
      if ($i <= $number) {
         // MetaInfos auslesen
         if ($article instanceof rex_article && !$article->isStartArticle()) {
            $headline = $article->getValue('name');
            $byline = $article->getValue('byline');
            $text = $article->getValue("teaser");            
            $img = $article->getValue("img");
            $articleId = $article->getId();          
            // Ausgabe
            echo '
               <div class="c12 item">
               <div class="c6">';
            if($img != '') {
               echo '<a href="'.rex_getUrl($articleId).'"><img src="index.php?rex_media_type=c6&rex_media_file='.$img.'" /></a>';
            }
            echo '   
               </div>
               <div class="c6">
                  <h2>
                     <a href="'.rex_getUrl($articleId).'">'.$headline.'</a>
                  <br><span class="byline">'.$byline.'</span>
                  </h2>
                  <hr class="line left" />
                  <p>'.$text.'</p>
               </div>
            </div>';
            }
         // Zähler +1
         $i++;
        }
   }
?>

Re: [gelöst] Artikelliste mit Teaser

Verfasst: 24. Okt 2019, 13:00
von gabiposch
Nachdem ich lange nach einer einfachen Blog-Lösung gesucht habe bin ich auf die Artikelliste mit Teasertext gekommen und habe es erweitert.

In Anlehnung daran - habe ich mir die Artikellist zurechtgebastelt - zu sehen unter: http://brk-schnaitsee.de/aktuelles/

1 Überschrift des Artikels (verlinkt)
2 Metadescription ist "Teasertext"
3 Neues Metadatenfeld - Teaserbild angelegt - wird im Artikelteaser angezeigt
4 Weiter lesen Text - verlinkt auf Hauptartikel
5 Wenn kein Bild vorhanden ist wird Text ohne Bild ausgegeben

Das ganze ist für die Demo-Version ausgelegt
Eingabe:

Code: Alles auswählen

<div id="artikelliste" >
  <div id="bereich1" class="">
    <div class="form-horizontal">
      <h3>Artikelliste</h3>
        <div class="form-group">
          <div class="col-sm-9 col-sm-push-3">
            Keine Eingabe notwendig
Bild und Text werden aus den Metadaten der Artikel in der Kategorie gebildet
          </div>
        </div>
    </div>
  </div>
</div>

<style>
#artikelliste {
  background: #f5f5f5;
  padding: 10px 30px 30px 15px;
  border: 1px solid #9da6b2;
}

#artikelliste h3 {
  font-size: 14px !important;
  padding: 10px;
  background: #DFE3E9;
  width: 100%;
  margin-bottom: 20px;
}
</style>

Ausgabe:

Code: Alles auswählen

<?php

$articles = rex_category::getCurrent()->getArticles();

if (count($articles)) {
  $output[] = '<div class="full container"><div class="row"><div class="col-md-8 col-md-offset-2">';
    foreach ($articles as $article) {
      if ($article->getValue('status') != 0&& $article->getValue('art_teaser') != '') { // Offline
        if ($article instanceof rex_article && !$article->isStartArticle()) {
            $output[] = '<div class="col-md-4"><img class="image-deco" src="index.php?rex_media_type=content&rex_media_file='.$article->getValue('art_teaser').'" alt="'.$desc.'"></div><div class="col-md-8"><a href="'.rex_geturl($article->getValue('id'), rex_clang::getCurrentId()).'">'.$article->getValue('name').'</a><p>'.$article->getValue('art_description').'</p>
<a href="'.rex_geturl($article->getValue('id'), rex_clang::getCurrentId()).'">mehr lesen...</a><div class="hline"></div></div>';
        }
      }
    }
  $output[] = '</div></div></div>';
} 

if (count($articles)) {
  $output[] = '<div class="full container"><div class="row"><div class="col-md-8 col-md-offset-2">';
    foreach ($articles as $article) {
      if ($article->getValue('status') != 0&& $article->getValue('art_teaser') == '') { // Offline
        if ($article instanceof rex_article && !$article->isStartArticle()) {
            $output[] = '<div class="col-md-4"></div><div class="col-md-8"><a href="'.rex_geturl($article->getValue('id'), rex_clang::getCurrentId()).'">'.$article->getValue('name').'</a><p>'.$article->getValue('art_description').'</p>
<a href="'.rex_geturl($article->getValue('id'), rex_clang::getCurrentId()).'">mehr lesen...</a><div class="hline"></div></div>';
        }
      }
    }
  $output[] = '</div></div></div>';
} 



if(!rex::isBackend()) {
  echo implode('',$output);
} else {
  echo '
  <div id="artikelliste" class="bereichswrapper">
    <div class="form-horizontal output">
     <h2>Artikelliste</h2>
       <div class="form-group">
         <div class="col-sm-12 control-label">
           <p>Die Artikelliste wird im Frontend ausgegeben.</p>
         </div>
       </div>
    </div>
  </div>

<style>
#artikelliste .bereichswrapper {
  margin: 5px 0 5px 0;
  background: #f5f5f5;
  padding: 5px 15px 5px 15px;
  border: 1px solid #9da6b2;
}

#artikelliste .control-label {
  text-align: left;
  font-weight: normal;
  font-size: 12px;
  margin-top: -6px;
}

#artikelliste  h2 {
  font-size: 12px !important;
  padding: 0 10px 10px 10px;
  margin-bottom: 15px;
  width: 100%;
  font-weight: bold;
  border-bottom: 1px solid #31404F;
}

</style>
';
}
Wieder mal bleibt mir nur zu sagen - REDAXO ist einfach SUPER