We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19889
    • 616 Posts
    Hello,

    I’m using the newsindex snippet below. However, it seems that the pagination part doesn’t produce acurate results. unfortunately, it is beyond my skill set to fix the snippet. it would be nice, if there is only one page that no page number would be added. in some instances, the snippet shows me 4 pages although there is no entry on the fourth page.

    I would appreciate if somebody could do some debugging or is there an alternative to this snippet.

    thank you in advance for your help.

    $resourceparent = isset($newsid) ? $newsid : $etomite->documentIdentifier;
             // the folder that contains blog entries 
    $output = '';
             // initialise the blog variable 
    $nrblogs = 1;
             // nr of blogs to show a short portion of 
    $nrblogstotal = 1;
             // total nr of blogs to retrieve 
    $lentoshow = 400;
             // how many characters to show of blogs 
    
    $resource = $etomite->getAllChildren($resourceparent, 'createdon', 'DESC', $fields='id, pagetitle, description, content, createdon, createdby');
    $limit=count($resource);
    if($limit<1) { 
       $output .= "No entries found.<br />"; 
    } 
    $nrblogs = $nrblogs<$limit ? $nrblogs : $limit; 
    if($limit>0) { 
       for ($x = 0; $x < $nrblogs; $x++) { 
    	  $tbl = $this->dbConfig['dbase'].".".$this->dbConfig['table_prefix']."manager_users";
          $sql = "SELECT username FROM $tbl WHERE $tbl.id = ".$resource[$x]['createdby']; 
          $rs2 = $etomite->dbQuery($sql);
          $limit2 = $etomite->recordCount($rs2); 
          if($limit2<1) { 
             $username .= "anonymous"; 
          } else { 
             $resourceuser = $etomite->fetchRow($rs2); 
             $username = $resourceuser['username']; 
             // strip the content 
             if(strlen($resource[$x]['content'])>$lentoshow) { 
                $rest = substr(strip_tags($resource[$x]['content']), 0, $lentoshow);
                $rest .= "<br /><br /><a href='[~".$resource[$x]['id']."~]'><span class='smalltext'>Weiter...</span></a>"; 
             } else { 
                $rest = $resource[$x]['content']; 
             } 
             $output .= "<div id='headers'>".$resource[$x]['pagetitle']."</div>".$rest."<br /><div class='author'><span class='smalltext'>Autor: <strong>".$username."</strong> am ".strftime("%d-%m-%y | %H:%M:%S", $resource[$x]['createdon'])."</span></div>"; 
          } 
       } 
    } 
    
    if($limit>$nrblogs) { 
       $output .= "<br /><br /><strong>Archivierte News</strong><ul>"; 
       for ($x = $nrblogs; $x < $limit; $x++) { 
          $output .= "<li><a href='[~".$resource[$x]['id']."~]'>".$resource[$x]['pagetitle']."</a></li>";          
       } 
    $output .= '</ul>';
    }
    
    return $output;


      • 19889
      • 616 Posts
      anybody???
      • Hi mmjaeger,

        Out of curiosity, where did the snippet come from, and what is it supposed to do? I’ll take a look at it very soon.

        Thanks!

          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • Hmmm...a paginator TV...
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
          • From looking and trying the snippet, it seems like a very simple/early copy of NewsListing. What were you hoping it would do that Newslisting does not?

            I agree with Sottwell, here. What we need is a good paginating and autoindex-building snippet. wink
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
              • 19889
              • 616 Posts
              Sorry, I should have put the whole snippet here - the listing of the news works - what’s causing troubles is the paginator at the bottom - the results produces are just not accurate - it e.g. show that there are four pages when in fact there are only three. Moreover, the page indication should be hidden if there is only one page.

              /*****************************************************************
              * NewsIndex
              * Created by: Wayne Chu
              * wayne at freethought dot ca
              * Sep 2, 2004
              *
              * Description:
              * Displays a paginated list of items in
              * the specified folder.
              *
              * Usage: [[NewsIndex?newsid={id}&desc={true|false}&sep={string}&pub=1]]
              * Variables: newsid - the ID of the folder to retrieve items from
              * desc - Optional boolean indicating if the page
              * description should be displayed
              * sep - Optional variable defining the separating
              * string between the date and the title
              * pub - Optional variable defining whether to publish
              * unpublished items (1 = published, 0 = unpublished)
              *
              ****************************************************************/

              $itemsPerPage = 5;
              $itemCss = "newslistitem";
              $itemCssDate = "newslistdate";
              $itemCssTitle = "newslisttitle";
              $itemCssPaging = "newslistpaging";
              $itemCssDescription = "newslistdesc";
              $separator = "
              ";
              //$dateFormat = "%F %j, %Y";
              setlocale (LC_TIME,"de_DE");
              $dateFormat = "%A, %e. %B %Y";


              if (isset($sep))
              $separator = $sep;

              // News Folder
              $id = isset($newsid) ? $newsid : $etomite->documentIdentifier;
              // Current Page
              $currPage = isset($_GET[’page’]) ? $_GET[’page’] : 1;

              // News Folder
              $folder = isset($newsid) ? $newsid : $etomite->documentIdentifier;
              // Current Page
              $currPage = isset($_GET[’page’]) ? $_GET[’page’] : 1;

              $items = $etomite->getAllChildren($folder, ’createdon’, ’DESC’, $fields=’id, pagetitle, description, content, createdon, createdby’);
              $totalItems = count($items);
              if ($totalItems < 1)
              return;

              $totalPages = (int)($totalItems / $itemsPerPage);
              if ($totalItems % $currPage > 0)
              $totalPages++;

              if ($currPage < 1 || $currPage > $totalPages)
              $currPage = 1;

              $firstItem = ($currPage * $itemsPerPage) - $itemsPerPage;
              $lastItem = ($currPage * $itemsPerPage);
              if ($lastItem > $totalItems)
              $lastItem = $totalItems;
              $output = "";

              // Display news items
              for ($i=$firstItem; $i<$lastItem; $i++) {
              $output .= "<div class=’" . $itemCss . "’>";
              $output .= "<span class=’" . $itemCssDate . "’>" . strftime($dateFormat, $items[$i][’createdon’]) . "</span>";
              $output .= "<span class=’" . $itemCssTitle . "’>";
              $output .= "<a href=’[~" . $items[$i][’id’] . "~]’>" . $items[$i][’pagetitle’] . "</a>";
              $output .= "</span>";
              $output .= "</div>";
              if (isset($desc) && $desc == true)
              $output .= "<div class=’" . $itemCssDescription . "’>" . $items[$i][’description’] . "</div>";
              $output .= $separator;
              }

              // Display Pagination

              $paginationGroup = (int)(($currPage-1) / 10);
              $firstDisplayPage = ($paginationGroup * 10) + 1;
              $lastDisplayPage = ($paginationGroup * 10) + 10;
              if ($lastDisplayPage > $totalPages)
              $lastDisplayPage = $totalPages;

              $output .= "<div class=’" . $itemCssPaging . "’>[ ";

              if ($totalItems < $itemsPerPage) {
              $output .= " <strong>1</strong> ";
              } else {
              if ($firstDisplayPage > 1)
              $output .= "&nbsp;<a href=’[~" . $etomite->documentIdentifier . "~]&page=" . ($firstDisplayPage-1) . "’>...</a>&nbsp;";

              for ($j=$firstDisplayPage; $j<=$lastDisplayPage; $j++) {
              if ($j == $currPage)
              $output .= "&nbsp;<strong>" . $j . "</strong>&nbsp;";
              else
              $output .= "&nbsp;<a href=’[~" . $etomite->documentIdentifier . "~]&page=" . $j . "’>" . $j . "</a>&nbsp;";
              }

              if ($lastDisplayPage < $totalPages)
              $output .= "&nbsp;<a href=’[~" . $etomite->documentIdentifier . "~]&page=" . $j . "’>...</a>&nbsp;";
              }

              $output .=" ]</div>";

              return $output;