1 Artikel gezielt auswählen und anteasern

Wie verwendet man Module oder Aktion und passt diese an.

1 Artikel gezielt auswählen und anteasern

Beitragvon Tizian » 17. Jul 2008, 13:26

moin, moin zusammen,

es gibt ein schönes modul von Mattias Beckmann, die Kategorienliste
http://www.redaxo.de/165-Moduldetails.html?module_id=176:

input:
Code: Alles auswählen
<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" />

output:
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)

      {

        $catId = $cat->getId();
        $catName = $cat->getName();
        $article = $cat->getArticles(1);

        if (is_array($article))
        {
          foreach ($article as $var)
          {

            $articleId = $var->getId();
            $articleName = $var->getName();
            $art = new rex_article($articleId);
            $articleContent = $art->getArticle(1);

            $articleContent = trim($articleContent);
            $articleContent = str_replace('</p>', ' </p>', $articleContent);
            $articleContent = str_replace('<br />', ' <br />', $articleContent);

            $articlePPath = $REX['MEDIAFOLDER'] . 'files/' . $var->getValue('file');

            $output = '';
            $words = explode(' ', $articleContent);
            $wordsCount = count($words);

            if ($wordsCount < $wordsPerArticle)
              $wEnd = $wordsCount;
            else
              $wEnd = $wordsPerArticle;

            for ($w = 0; $w < $wEnd; $w++)
            {
              $output .= $words[$w] . ' ';
            }

            $output = trim($output);

            $isCloseParagraph = substr($output, -4);
            $link = '<a href="' . rex_getUrl($articleId) . '" class="more"> ... mehr</a>';
            $newString = $link . '</p>';

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

         //   print '<h3>'.$articleName.'</h3>';
if ($_GET["article_id"] == 2)


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

         
        }
      }
    }
  }
}
?>

benutze ich so unter redaxo 4.1 und funktioniert.

ich würde es jetzt gerne umschreiben, kann aber nur rudimentär php ...

ich möchte keine kategorienliste sondern nur einen bestimmten artikel der website wählen können und bestimmen, wieviele wörter des inhalts der spalte x dargestellt werden sollen.

im input sähe das bei mir so aus:
Code: Alles auswählen
Artikel, der angeteasert werden soll:
<br /><br />
REX_LINK_BUTTON[1]
<br /><br />
<strong>Anzahl der Wörter</strong><br />
<input name="VALUE[2]" value="REX_VALUE[2]" class="inp100" />


wie muss ich jetzt den output anpassen, damit er nicht alle artikel der kategorie ausliest?

ist möglicherweise nur die zeile
Code: Alles auswählen
$article = ooarticle::getArticleById(REX_LINK_ID[1]);

die an der richtigen stelle die verweise auf die kategorie" ersetzt.
nur ich weis nicht wie ...

kann mir jemand unter die arme greifen?

danke!
schöne grüße
tizian
********************************
ansichtsache TM
Tizian
 
Beiträge: 113
Registriert: 4. Apr 2008, 10:58
Wohnort: Bremen

Beitragvon Markus.Staab » 17. Jul 2008, 14:10

Hi tizian,

entferne die Schleife um den Schleifenkörper und setze die Artikel Id des LinkButtons direkt in den Artikel ein.

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

Beitragvon Tizian » 17. Jul 2008, 21:00

hallo markus,

das war leider noch nicht konkret genug.
ich habe mich mal versucht und denke ich bin auf der richtigen spur,
habe aber leider das prinzip noch nicht ganz verstanden.

mein code im output jetzt:
Code: Alles auswählen
<?php
$article = ooArticle::getArticleById(REX_LINK_ID[1]);

$wordsPerArticle = "REX_VALUE[2]";

            $articleId = $article->getId(REX_LINK_ID[1]);
            $articleContent = $article->getArticle(1);

            $articleContent = trim($articleContent);
            $articleContent = str_replace('</p>', ' </p>', $articleContent);
            $articleContent = str_replace('<br />', ' <br />', $articleContent);

//$articlePPath = $REX['MEDIAFOLDER'] . 'files/' . $var->getValue('file');

            $output = '';
            $words = explode(' ', $articleContent);
            $wordsCount = count($words);

            if ($wordsCount < $wordsPerArticle)
              $wEnd = $wordsCount;
            else
              $wEnd = $wordsPerArticle;

            for ($w = 0; $w < $wEnd; $w++)
            {
              $output .= $words[$w] . ' ';
            }

            $output = trim($output);

            $isCloseParagraph = substr($output, -4);
            $link = '<a href="' . rex_getUrl(REX_LINK_ID[1]) . '" class="more"> ... mehr</a>';
            $newString = $link . '</p>';

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

//if ($_GET["article_id"] == 2)

print  '<div class="teaser">'.$output.'</div>' ;     
?>


liefert leider noch diese fehlermeldungen:
im frontend:
Code: Alles auswählen
Fatal error: Call to undefined method OOArticle::getArticle() in /mnt/web4/20/37/51618837/htdocs/2008/redaxo/include/classes/class.rex_article.inc.php(250) : eval()'d code on line 10


im backend (nach block speichern):
Code: Alles auswählen
Fatal error: Call to undefined method OOArticle::getArticle() in /mnt/web4/20/37/51618837/htdocs/2008/redaxo/include/classes/class.rex_article.inc.php(596) : eval()'d code on line 53


dankbar für den rettenden hinweis
schöne grüße
tizian
********************************
ansichtsache TM
Tizian
 
Beiträge: 113
Registriert: 4. Apr 2008, 10:58
Wohnort: Bremen

Beitragvon Markus.Staab » 18. Jul 2008, 07:15

Hi,

ersetze mal

Code: Alles auswählen
$article = ooArticle::getArticleById(REX_LINK_ID[1]);

$wordsPerArticle = "REX_VALUE[2]";

            $articleId = $article->getId(REX_LINK_ID[1]);
            $articleContent = $article->getArticle(1);

durch

Code: Alles auswählen
$article = new rex_article(REX_LINK_ID[1]);
$articleId = REX_LINK_ID[1];

$wordsPerArticle = "REX_VALUE[2]";

            $articleContent = $article->getArticle(1);


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

Danke! Wieder was gelernt.

Beitragvon Tizian » 18. Jul 2008, 08:19

hi markus,
jetzt geht's.

input
Code: Alles auswählen
<strong>Artikel, der angeteasert werden soll:</strong>
<br /><br />
REX_LINK_BUTTON[1]
<br />
<strong>Anzahl der Wörter</strong><br />
<input name="VALUE[2]" value="REX_VALUE[2]" class="inp100" />

output
Code: Alles auswählen
<?php
$article = new rex_article(REX_LINK_ID[1]);
$articleId = REX_LINK_ID[1];
$wordsPerArticle = "REX_VALUE[2]";
            $articleContent = $article->getArticle(1);
            $articleContent = trim($articleContent);
            $articleContent = str_replace('</p>', ' </p>', $articleContent);
            $articleContent = str_replace('<br />', ' <br />', $articleContent);
            $output = '';
            $words = explode(' ', $articleContent);
            $wordsCount = count($words);
            if ($wordsCount < $wordsPerArticle)
              $wEnd = $wordsCount;
            else
              $wEnd = $wordsPerArticle;
            for ($w = 0; $w < $wEnd; $w++)
            {
              $output .= $words[$w] . ' ';
            }
            $output = trim($output);
            $isCloseParagraph = substr($output, -4);
            $link = '<a href="' . rex_getUrl(REX_LINK_ID[1]) . '" class="more"> ... mehr</a>';
            $newString = $link . '</p>';
            if ($isCloseParagraph == '</p>')
            {
              $output = substr_replace($output, $newString, -4);
            }
            else
            {
              $output .= $newString;
            }
            print  '<div class="teaser">'.$output.'</div>' ;     
?>


danke und
schöne grüße
tizian
********************************
ansichtsache TM
Tizian
 
Beiträge: 113
Registriert: 4. Apr 2008, 10:58
Wohnort: Bremen


Zurück zu Module/Aktionen [R4]

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 2 Gäste