We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11526
    • 93 Posts
    I use a newslisting snippet om my homepage. This snippet shows the 6 most recent documents in a folder. The first 3 with an intro of 200 characters and the next 3 only the title.

    But in the intro it shows also the title, that i put on the first line of my newsitems between <h1> - tags.

    I would like to change the snippet so that the intro it shows only starts after the </h1>- closing tag, so the titles of the 3 most recent newsitems will not display in the intro...

    Who can help me?

    The code of the snippet:
    $resourceparent = isset($newsid) ? $newsid : $etomite->documentIdentifier;
             // the folder that contains blog entries 
    $output = '';
             // initialise the blog variable 
    $nrblogs = 3;
             // nr of blogs to show a short portion of 
    $nrblogstotal = 6;
             // total nr of blogs to retrieve 
    $lentoshow = 200;
             // how many characters to show of blogs 
    
    $resource = $etomite->getActiveChildren($resourceparent, 'createdon', 'DESC', $fields='id, pagetitle, description, content, createdon, createdby');
    $limit=count($resource);
    if($limit<1) { 
       $output .= "No newsitems.<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($resource[$x]['content'], 0, $lentoshow); 
                $rest .= "..."; 
             } else { 
                $rest = $resource[$x]['content']; 
             } 
             $output .= "<fieldset><legend><b>".$resource[$x]['pagetitle']."</b></legend>".$rest."<br /><br /><div style='text-align:right;'><a href='[~".$resource[$x]['id']."~]'>More on this story: '".$resource[$x]['pagetitle']."'</a>   </div></fieldset><br />"; 
          } 
       } 
    } 
    
    if($limit>$nrblogs) { 
       $output .= "<br /><br /><b>Older news</b><br />"; 
       for ($x = $nrblogs; $x < $nrblogstotal; $x++) { 
          $output .= "> <a href='[~".$resource[$x]['id']."~]'>".$resource[$x]['pagetitle']."</a><br />";          
       } 
    }
    
    return $output;
      • 11526
      • 93 Posts
      After a few more attemps, i came up with the following solution... I am no hero when it comes to php-code and so i am really pleased with myself. But maybe someone has suggestions for me to improve the code below...

      $resourceparent = isset($newsid) ? $newsid : $etomite->documentIdentifier;
               // the folder that contains blog entries 
      $output = '';
               // initialise the blog variable 
      $nrblogs = 3;
               // nr of blogs to show a short portion of 
      $nrblogstotal = 6;
               // total nr of blogs to retrieve 
      $lentoshow = 250;
               // how many characters to show of blogs 
      $endtitle = '</h1>';
      
      $resource = $etomite->getActiveChildren($resourceparent, 'createdon', 'DESC', $fields='id, pagetitle, description, content, createdon, createdby');
      $limit=count($resource);
      if($limit<1) { 
         $output .= "Geen nieuwsitems gevonden.<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']; 
               // remove title
               $content = strstr($resource[$x]['content'], $endtitle);
      
               // strip the content 
               if(strlen($content)>$lentoshow) { 
                  $rest = substr($content, 0, $lentoshow); 
                  $rest .= "..."; 
               } else { 
                  $rest = $content; 
               } 
               $output .= "<fieldset><legend><b>".$resource[$x]['pagetitle']."</b></legend>".$rest."<br /><br /><div style='text-align:right;'><a href='[~".$resource[$x]['id']."~]'>Volledig artikel: '".$resource[$x]['pagetitle']."'</a>   </div></fieldset><br />"; 
            } 
         } 
      } 
      
      if($limit>$nrblogs) { 
         $output .= "<br /><br /><b>Ouder nieuws (bekijk ook het nieuwsarchief op deze website)</b><br />"; 
         for ($x = $nrblogs; $x < $nrblogstotal; $x++) { 
            $output .= "> <a href='[~".$resource[$x]['id']."~]'>".$resource[$x]['pagetitle']."</a><br />";          
         } 
      }
      
      return $output;
        • 18397
        • 3,250 Posts
        Wow! That is an EXTREMELY old version of NewsListing. It still has etomite as the document object!

        Please download the latest version here: http://modxcms.com/forums/index.php/topic,1235.html

        For instructions on how to customize the output go here: http://modxcms.com/NewsListing.html and choose Customization
        Creating a new template from the Table Of Contents.

        Hope that helps!