[phpBB Debug] PHP Warning: in file [ROOT]/ext/tas2580/seourls/event/listener.php on line 213: Undefined array key "FORUM_NAME"
REDAXO Forum • Infinite Artikel Navigation (Blätternavigation)
Seite 1 von 1

Infinite Artikel Navigation (Blätternavigation)

Verfasst: 30. Mai 2015, 12:12
von stefanendress
Hallo Leute,

ich würde gerne eine Artikelnavigation bauen, mit der man endlos durch die artikel der aktuellen Kategorie blättern kann und den Startartikel überspringt. Ich versuche mal darzustellen wie es im Moment funktioniert und wie es sein sollte.

Ist zustand:

First article
previous article (startarticle) – next article

Article in between
previous articlenext article

Last article
nothing (gibt gar nichts aus)

_____

So sollte es sein:

First project
previous article (last project) – next article

Article in between
previous articlenext article

Last Article
previous articlenext article (first project)


Habe schon einiges ausprobiert, komm aber leider nicht mehr weiter und würde mich super freuen wenn jemand eine Idee hätte. Das Ausgangsmodul habe ich hier gefunden http://usysto.net/blog/redaxo_artikel_blaettern.php, jedoch ein wenig umgebaut und aufgeräumt.

Danke,
Stefan

Code: Alles auswählen

<?php

	$categoryId = $this->getValue('category_id');
	$articleId 	= $this->getValue('article_id');

	// all articles from current category
	$articles = OOArticle::getArticlesOfCategory($categoryId, true);

	// reverse articles
	$reversedArticles = array_reverse($articles);

	// vars
	$number 	= 0;
	$curNumber 	= 0;
	$arrArt 	= array();
	$output 	= '';

	// all online articles from this category
	foreach ($reversedArticles as $article) { 
		if (is_object($article)) {

			// count
			$number++; 

			// current article
			if ($article->getId() == $articleId) {
				$curNumber 		= $number;
				$prev_number 	= $number + 1;
				$next_number 	= $number - 1;
			}

			// new array with all articles
			$arrArt[$number] = $article; 
		}
	}

	$nextName 	= $arrArt[$next_number]->getName();
	$prevName 	= $arrArt[$prev_number]->getName();

	$nextUrl 	= rex_getUrl($arrArt[$next_number]->getId());
	$prevUrl 	= rex_getUrl($arrArt[$prev_number]->getId());

	// if next article exists
	if (is_object($arrArt[$next_number])) { 
		$nextart = ' <a href="'.$nextUrl.'">'.$nextName.'</a> ';
	}

	// if prev article exists
	if (is_object($arrArt[$prev_number])) { 
		$prevart = ' <a href="'.$prevUrl.'">'.$prevName.'</a> ';
	}

	// if another article exists
	if (isset($nextart) || isset($prevart)) { 
		$output = ''.$prevart.' '.$nextart.'';
	}

	echo $output;

?>

Re: Infinite Artikel Navigation (Blätternavigation)

Verfasst: 5. Aug 2015, 10:27
von gupi
Ungetestet, aber sollte funktionieren.

Code: Alles auswählen

    <?php

       $categoryId = $this->getValue('category_id');
       $articleId    = $this->getValue('article_id');

       // all articles from current category
       $articles = OOArticle::getArticlesOfCategory($categoryId, true);

       //Startartikel entfernen
       unset($articles[0]);

      // reverse articles
      $reversedArticles = array_reverse($articles);

 
      //letzten Index des Arrays ermitteln
      $high_index = count($reversedArticles) - 1;

      // vars
       $number    = 0;
       $curNumber    = 0;
       $arrArt    = array();
       $output    = '';

       // all online articles from this category
       foreach ($reversedArticles as $article) {
          if (is_object($article)) {

             // count
             $number++;

             // current article
             if ($article->getId() == $articleId) {
                $curNumber       = $number;
                $prev_number    = $number + 1;
                if ($prev_number > $high_index) {
                   $prev_number = 0;
                }
                $next_number    = $number - 1;
                if ($next_number < 0) {
                   $prev_number = $high_index;
                }
            }

             // new array with all articles
             $arrArt[$number] = $article;
          }
       }

       $nextName    = $arrArt[$next_number]->getName();
       $prevName    = $arrArt[$prev_number]->getName();

       $nextUrl    = rex_getUrl($arrArt[$next_number]->getId());
       $prevUrl    = rex_getUrl($arrArt[$prev_number]->getId());

       // if next article exists
       if (is_object($arrArt[$next_number])) {
          $nextart = ' <a href="'.$nextUrl.'">'.$nextName.'</a> ';
       }

       // if prev article exists
       if (is_object($arrArt[$prev_number])) {
          $prevart = ' <a href="'.$prevUrl.'">'.$prevName.'</a> ';
       }

       // if another article exists
       if (isset($nextart) || isset($prevart)) {
          $output = ''.$prevart.' '.$nextart.'';
       }

       echo $output;

    ?>
LG
Gunter

Re: Infinite Artikel Navigation (Blätternavigation)

Verfasst: 8. Sep 2016, 10:28
von alexplus
Funktionierte nicht.

Getestet und funktioniert:

Code: Alles auswählen

<?php

$categoryId = $this->getValue('category_id');
$articleId    = $this->getValue('article_id');

// all articles from current category
$articles = OOArticle::getArticlesOfCategory($categoryId, true);

// reverse articles
$reversedArticles = array_reverse($articles);

// vars
$number    = 0;
$curNumber    = 0;
$arrArt    = array();
$output    = '';

// all online articles from this category
foreach ($reversedArticles as $article) {

    if (is_object($article)) {

        // count
        $number++; 
        $arrArt[$number] = $article; 

        // current article
        if ($article->getId() == $articleId) {
            $curNumber       = $number;
            $prev_number    = $number + 1;
            $next_number    = $number - 1;
        }
    }
}

if(is_object($arrArt[$next_number])) {
    $nextName    = $arrArt[$next_number]->getName();
    $nextUrl    = rex_getUrl($arrArt[$next_number]->getId());
    $output .= ' <a href="'.$nextUrl.'">'.$nextName.'</a> ';


}
   if(is_object($arrArt[$prev_number])) {
       $prevName    = $arrArt[$prev_number]->getName();
       $prevUrl    = rex_getUrl($arrArt[$prev_number]->getId());
       $output .= ' <a href="'.$prevUrl.'">'.$prevName.'</a> ';
   }

      echo $output;

?>