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
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?
$resource = $modx->getAllChildren($resourceparent, 'createdon', 'DESC', $fields='id, pagetitle, description, introtext, content, createdon, createdby');
// 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']; }
// 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']; }
$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;
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.
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