Teaser soll nur für eine Spalte gelten

Wie verwendet man Module oder Aktion und passt diese an.

Teaser soll nur für eine Spalte gelten

Beitragvon catchmich » 8. Mär 2010, 12:09

Hallo,

ich habe auf meiner Seite ein Template in dem 3 Spalten mit jeweils individuellem Inhalte sind. Nun verwenden ich auf einer Seite in der Spalte 2 das Modul angepasster Teaser (http://www.redaxo.de/165-0-moduldetails.html?module_id=66). Nun soll er aber nicht alle Spalten der Artikel anteasern, sondern eben auch nur den Inhalt der Spalte zwei.

Kann mir dort jemand weiterhelfen?

Redaxoversion: 4.2.1

Viele Grüße
catchmich
 
Beiträge: 3
Registriert: 17. Jul 2006, 14:43

Beitragvon darwin » 8. Mär 2010, 20:05

Hi,

probier mal $this->getArticle(2) ...
bzw. bei dem Script:
Code: Alles auswählen
$articleContent = $article->getArticle(2);


2 steht hierfür für die CTYPE ID:2

grz. Chris
Benutzeravatar
darwin
 
Beiträge: 1232
Registriert: 2. Jan 2007, 16:10
Wohnort: LA

Genau

Beitragvon nitzer » 11. Mär 2010, 16:15

Genau das gleiche brauchte ich gestern auch.

Ich hab den Teaser noch um die Möglichkeit die Kategorie auszuwählen erweitert. Ebenfalls kann die Spalte durch ein einfaches Drop-Down ausgewählt werden. Ok - eigentlich müsste man noch abfragen ob die Spalten überhaupt existieren.

Aber so reichte das für mich:

Eingabe:
Code: Alles auswählen

<?php
// -- modified by Andreas Otte        --
// -- otte@otte.net                         --
// -- Version 1.0                            --
// ----------------------------------------

function PrintCategorieOptions($cat = null) {
   $selectCats = null;
   if ( is_int( $cat)) {
      $selectCats = array( OOCategory::getCategoryById( $cat));
   } else {
      $selectCats = OOCategory::getRootCategories();
   }

   foreach ( $selectCats as $selectCat) {
      add_cat_option( $selectCat);
   }
}


function add_cat_option( &$cat, $groupName = '') {
   if( empty( $cat)) {
      return;
   }

   print_link($cat->getName(), $cat->getId(), $groupName);

   if ( $cat->getChildren()) {
      $childs = $cat->getChildren();
     
      foreach ( $childs as $child) {
         if ($child->getChildren()) {
            add_cat_option( $child, $groupName."&nbsp;&nbsp;");
         } else {
            add_cat_option( $child, $groupName."&nbsp;&nbsp;");
         }
      }
   }
}

function print_link($catName, $catId, $groupName) {
   global $selectedCat;
   if ( "REX_VALUE[4]" == $catId) {
      // selected
      echo "<option value=\"" . $catId . "\" selected>" . $groupName.$catName . "</option>\n";
   } else {
      echo "<option value=\"" . $catId . "\">" . $groupName.$catName . "</option>\n";
   }
}



?>
<strong>Kategorie:</strong>
<br />
<select name="VALUE[4]">
   <?php PrintCategorieOptions(); ?>
</select>
<br />
<br />
<strong>Anzahl der Artikel pro Seite</strong><br />
<input name="VALUE[1]" value="REX_VALUE[1]" class="inp100" /><br />
<br />
<strong>Anzahl der Wörter pro Artikel</strong><br />
<input name="VALUE[2]" value="REX_VALUE[2]" class="inp100" /><br />
<br />
<strong>Sortierung nach</strong><br />
<select name="VALUE[3]" ><?
  foreach (array("prio","updatedate","createdate","name") as $value) {
    echo '<option value="'.$value.'" ';
    if ( "REX_VALUE[3]"=="$value" ) {
      echo 'selected="selected" ';
    }
    echo '>'.$value.'</option>';
  }
?></select>
<br />
<br />
<strong>Welche Artikelspalte soll ausgelesen werden?</strong>
<br />
<select name="VALUE[6]" >
<?php
foreach (array("1","2","3","4","5","6") as $value) {
   echo '<option value="'.$value.'" ';
   
   if ( "REX_VALUE[6]"=="$value" ) {
      echo 'selected="selected" ';
   }
   echo '>'.$value.'</option>';
}
?>
</select>


Ausgabe:
Code: Alles auswählen
<?php
//---MODULE MODIFIED BY--------------------------
//-- a-concept internet.studio
//-- Sven Albert-Pedersen
//-- http://a-concept.de / http://svenalbert.de
//-----------------------------------------------
//-- version 1.3
//-- date 09-jan-2009
//-----------------------------------------------
//-- Nachträglich eingefügt:
//--
//-- * Zählen und Schließen von DIVs & SPANs
//-- * Auswahl der Sortierung nach Prio
//-- * Ausblendung eines Bildes im Artikel
//-- * Funktionalität mit mehrsprachigen Webseiten
//-- * Zurück-Link, wenn Seite über den Teaser aufgerufen wurde
//-- * v1.24 Texte für $nextLink und $backLink im oberen Bereich der Datei
//-- * v1.3 Schließen der Tags in einen Array und eine For-Schleife verpackt
//--
//-- Bugfixes:
//-- v1.23 Moduleingabe: Select hatte falschen Variablennamen
//-----------------------------------------------

//---BEZEICHNUNG DER BLÄTTER- und WEITER-LINKS---
//--
//--
$backLink_text = 'vorige Seite';
$nextLink_text = 'nächste Seite';
$moreLink_text = 'weiterlesen';
//--
//--
//-----------------------------------------------


$itemsPerSide = "REX_VALUE[1]";
$wordsPerArticle = "REX_VALUE[2]";
$sorting_order = "REX_VALUE[3]";
$catId = "REX_VALUE[4]";

//echo $sorting_order;

// Nur im Frontend
//if (!$REX['REDAXO']):

// Sortierfunktionen

// 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; } }

// 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; } }



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

$articles = array();

// foreach ( $cats as $catId) {
//  $cat = OOCategory::getCategoryById( $catId);
 
$cat = OOCategory::getCategoryById($catId);
$childs = $cat->getArticles( true);

if ( is_array( $childs)) {
if('REX_VALUE[5]') {
    usort($childs, 'sortArticlesBy'.$sorting_order);
}
 
 

  // 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) {

  if ($sorting_order == "updatedate") {
    usort( $articles, "sortArticlesByUpdateDate");
  }
  elseif ($sorting_order == "prio") {
#    usort( $articles, "sortArticlesByPrio");
  }
  elseif ($sorting_order == "name") {
    usort( $articles, "sortArticlesByName");
  }
  elseif ($sorting_order == "createdate") {
    usort( $articles, "sortArticlesByCreateDate");
  }

}

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

foreach ( $article_list as $ooarticle) {
   
   if ($ooarticle->isOnline(true)) {
      $articleId = $ooarticle->getId();

      $article = new article();


    $article->setClang($REX['CUR_CLANG']); // lt. Kommentar, openmind, 01-feb-2007
      $article->setArticleId( $articleId);
      
      // Article-Ctype angeben
      $ctype = "REX_VALUE[6]";
      $articleContent = $article->getArticle($ctype);
      
      // DIV-Container mit Bildern entfernen
#      $articleContent = preg_replace('/<div style=\".*?<\/div>/', "",$articleContent);
      $articleContent = preg_replace('/<div class=\"image float_(right|left)\" .*?<\/div>/', "",$articleContent);
   
      // 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);
   
#    echo 'count: <b>'.$wordsCount.'</b>';
#    echo 'teaser: <b>'.$wordsPerArticle.'</b>';
   
    if ($wordsCount < $wordsPerArticle) {
      $wEnd = $wordsCount;
#      echo 'KLEINER';
      $link = '';
      }
    else {
      $wEnd = $wordsPerArticle;
#      echo 'GROESSER GLEICH';
      $link = '&nbsp;… <a href="'.rex_getUrl($articleId, $REX['CUR_CLANG'], array('goback' => "REX_ARTICLE_ID")).'" title="'. $moreLink_text .'">'. $moreLink_text .'&nbsp;»</a>';
      }
   
    for ($w=0;$w<$wEnd;$w++) {
      $output .= $words[$w]." ";
      }
   
    // Leerzeichen entfernen am Anfang und Ende des Strings
    $output = trim($output);
   
    $isCloseParagraph = substr($output,-4);
    $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
      // ----------------------------------------------------------
      // MODIFIED by Sven Albert-Pedersen * alfa-x (at) web (dot) de
      
      $openingTags = array("<a "  , "<i>"  , "<strong>"  , "<b>"  , "<li"        , "<ul"   , "<span"   , "<div");
      $closingTags = array("</a>" , "</i>" , "</strong>" , "</b>" , "</li>"      , "</ul>" , "</span>" , "</div>");
      $substitTags = array("</a>" , "</i>" , "</strong>" , "</b>" , "</li></ul>" , "</ul>" , "</span>" , "</div>");
      
      for($i=0; $i < count($openingTags); $i++)
      {
         $opening = '';      $closing = '';      $missing = '';
         $opening = substr_count($output, $openingTags[$i]);
         $closing = substr_count($output, $closingTags[$i]);
         $missing = $opening - $closing;
         
         if ($opening > $closing)
         {
            while ($missing > 0)
            {
               $output .= $substitTags[$i];
               $missing = $missing - 1;
            }
         }
      }
      
      // ----------------------------------------------------------
      // END MODIFICATION

      print '<div class="newsbox">'.$output.'</div>';
   }
}

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


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

$link_format = '<a href="'.rex_getUrl("REX_ARTICLE_ID", $REX['CUR_CLANG'], array('start'=>'%s')).'">%s</a>';

// Vorherige Seite Link
if ( $prevStart !== '') {
  $backLink = sprintf( $link_format, $prevStart, '«&nbsp;'.$backLink_text);
}

// Nächste Seite
if ( $nextStart !== '') {
  $nextLink = sprintf( $link_format, $nextStart, $nextLink_text.'&nbsp;»');
}

if ($backLink != "" AND $nextLink != "") {
   print '<div class="teaserNav"><p>'.$backLink.'&nbsp;|&nbsp;'.$nextLink.'</p></div>';
}
elseif ($nextLink != "") {
   print '<div class="teaserNav"><p>'.$nextLink.'</p></div>';
}
elseif ($backLink != "") {
   print '<div class="teaserNav"><p>'.$backLink.'</p></div>';
}

//endif;
// print $catId;
?>
nitzer
 
Beiträge: 180
Registriert: 16. Okt 2006, 21:53
Wohnort: Erkrath


Zurück zu Module/Aktionen [R4]

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast