We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4266
    • 70 Posts
    I'd like to modify NewsListing using template variables in order to show in a news listing a small preview image and separate description (I don’t like not smart truncate function).
    I'm not the GURU in templates variables and PHP so hope you have some ideas smiley
      • 32963
      • 1,732 Posts
      I'd like to modify NewsListing using template variables in order to show in a news listing a small preview image and separate description (I don’t like not smart truncate function).
      I'm not the GURU in templates variables and PHP so hope you have some ideas smiley

      I would like to recommend that you use the introtext field when generating a news page summary or description. In this field you can store HTML, text , etc

      EDITED: introtext can be found in the site_content table
        xWisdom
        www.xwisdomhtml.com
        The fear of the Lord is the beginning of wisdom:
        MODx Co-Founder - Create and do more with less.
        • 4266
        • 70 Posts
        Thank you for a reply! But I have no idea what to start with... :?

        As I understand that I need to create the new template variable with richtext input type and append the introtext field from my MySQL-database. And then to modify NewsListing snippet in order to display the content of the introtext field.

        Xwisdom, please :roll: , could you tell me how to do it in a 1-2-3 manner?
          • 32963
          • 1,732 Posts

          As I understand that I need to create the new template variable with richtext input type and append the introtext field from my MySQL-database. And then to modify NewsListing snippet in order to display the content of the introtext field.

          Well you could create a new TV with richtext input called introtext. This will overwrite the existing introtext or summary field. You would have to modify the existing NewListing snippet to use TV functions


          Xwisdom, please :roll: , could you tell me how to do it in a 1-2-3 manner?

          This will work without the creating a new TV

          In the original newslisting snippet change modify line 20 to show:

          $resource = $modx->getAllChildren($resourceparent, 'createdon', 'DESC', $fields='id, pagetitle, description, introtext, content, createdon, createdby');
          


          Note the "introtext" as added to the above

          then change lines 35-41 from:

                   // strip the content 
                   if(strlen($resource[$x]['content'])>$lentoshow) { 
                      $rest = substr($resource[$x]['content'], 0, $lentoshow); 
                      $rest .= "...<br />    <a href='[~".$resource[$x]['id']."~]'>More on this story ></a>"; 
                   } else { 
                      $rest = $resource[$x]['content']; 
                   } 
          


          to

          		// show summary
          		if(strlen($resource[$x]['introtext'])>0) {
                      $rest = $resource[$x]['introtext'];
          			if(strlen($resource[$x]['content'])>0) $rest .= "...<br />    <a href='[~".$resource[$x]['id']."~]'>More on this story ></a>"; 
          		} else if(strlen($resource[$x]['content'])>$lentoshow) { 
          			// strip the content 
                      $rest = substr($resource[$x]['content'], 0, $lentoshow); 
                      $rest .= "...<br />    <a href='[~".$resource[$x]['id']."~]'>More on this story ></a>"; 
                  } else { 
                      $rest = $resource[$x]['content']; 
                  } 
          


          This will allow you to use the document's summary (introtext) field with HTML syntax for news summary headers. If no summary is available it will use a portion of the content field as it would normally.

          That's it!
            xWisdom
            www.xwisdomhtml.com
            The fear of the Lord is the beginning of wisdom:
            MODx Co-Founder - Create and do more with less.
            • 4266
            • 70 Posts
            Xwizdom, hi!

            I've changed the snippet code exactly as you say, but the introtext content doesn't display by NewsListing snippet :? The snippet shows only truncate text of the articles.

            Coud you check up my code:

            $resourceparent = isset($newsid) ? $newsid : $etomite->documentIdentifier;
                     // the folder that contains blog entries 
            $output = '';
                     // initialise the blog variable 
            $nrblogs = 2;
                     // nr of blogs to show a short portion of 
            $nrblogstotal = 100;
                     // total nr of blogs to retrieve 
            $lentoshow = 550;
                     // how many characters to show of blogs 
            
            
            
            $resource = $etomite->getAllChildren($resourceparent, 'createdon', 'DESC', $fields='id, pagetitle, description, introtext, 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']; 
            
            	 
            // show summary
            if(strlen($resource[$x]['introtext'])>0) {
            $rest = $resource[$x]['introtext'];
            if(strlen($resource[$x]['content'])>0) $rest ."...<br />    <a href='[~".$resource[$x]['id']."~]'>More on this story ></a>";
            } else if(strlen($resource[$x]['content'])>$lentoshow) {
            // strip the content
            $rest = substr($resource[$x]['content'], 0, $lentoshow);
            $rest .= "...<br />    <a href='[~".$resource [$x]['id']."~]'>More on this story ></a>";
            } else {
            $rest = $resource[$x]['content'];
            }
             
            		 
            		 
                     $output .= "<fieldset><legend>".$resource[$x]['pagetitle']."</legend>".$rest."<br /><div style='text-align:right;'>Author: <b>".$username."</b> on ".strftime("%d-%m-%y %H:%M:%S", $resource[$x]['createdon'])."</div></fieldset>"; 
                  } 
               } 
            } 
            
            if($limit>$nrblogs) { 
               $output .= "<br /><br /><b>Older news</b><br />"; 
               for ($x = $nrblogs; $x < $limit; $x++) { 
                  $output .= "> <a href='[~".$resource[$x]['id']."~]'>".$resource[$x]['pagetitle']."</a><br />";          
               } 
            }
            
            return $output;
              • 32963
              • 1,732 Posts
              what version of MODx are you using?

              Are you using a TV introtext field or the Summary field on the document page?

              If you should enter some text inside the Summary field of the document it should be displayed.

              This line checks for it :

              if(strlen($resource[$x]['introtext'])>0) {
                xWisdom
                www.xwisdomhtml.com
                The fear of the Lord is the beginning of wisdom:
                MODx Co-Founder - Create and do more with less.
                • 4266
                • 70 Posts
                In my current version of MODx native summary field works fine and it is displaying in the NewsListing. But when I move summary content to the introtext-TV it is not displaying. Instead the first XXX letters of the article appear.

                I'm using MODx+bugfx downloaded from http://www.sottwell.com/downloads/ a few weeks ago. But today I've found that this site had changed it's skin (now it is green, not blue as a few weeks ago). So it seems I have not the last version of MODx. Xwisdom, may be you could send me the last version?

                P.S. By the way, I've translated MODx lang-file on russian and can share it.
                  • 32963
                  • 1,732 Posts
                  In my current version of MODx native summary field works fine and it is displaying in the NewsListing. But when I move summary content to the introtext-TV it is not displaying. Instead the first XXX letters of the article appear.

                  I'm using MODx+bugfx downloaded from http://www.sottwell.com/downloads/ a few weeks ago. But today I've found that this site had changed it's skin (now it is green, not blue as a few weeks ago). So it seems I have not the last version of MODx. Xwisdom, may be you could send me the last version?

                  Ok, the code I showed you only works with the native summary field. It will not work the the TV fields. Future versions of such snippets will most likely support TV fields


                  P.S. By the way, I've translated MODx lang-file on russian and can share it.

                  Sounds great! You can post it inside the forums

                  Thank you for use MODx

                  Best regards,
                    xWisdom
                    www.xwisdomhtml.com
                    The fear of the Lord is the beginning of wisdom:
                    MODx Co-Founder - Create and do more with less.
                  • Don't mind the color of the pages, that's what I do at 3 AM when I can't sleep. The files are still the same.
                      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
                      • 4266
                      • 70 Posts
                      Ok, the code I showed you only works with the native summary field. It will not work the the TV fields. Future versions of such snippets will most likely support TV fields

                      So is the problem with MODx or NewsListing snippet? I'm sure that richtext summary field is a HOT topic :!: Of course you may insert an image html-code in a plain-text field, but it is not comfortable at all :? .