homepagedisplay by Mark Kaplan
Instructions: Please create a tv with a checkbox titled something like "Promote to home page". Then look up in the db which tmplvarid it is in the site_tmplvar_contentvalues table. If it is your first tv ever it will be 1. Enter this value for $tempid. Then add this snippet to your homepage and promote some documents. You are set. If you have any text in the summary field it will be displayed instead of the shortened content by default (very handy if you experience formatting issues)
Example of TV:
Note: I changed the english lang file to use options instead of template variables to make it easier for the end user.
If you need assistance post here in this thread, I will be glad to help.
Code:
//homepagedisplay by Mark Kaplan
//Please create a tv with a checkbox titled something like "Promote to home page". Then look up in the db which tmplvarid it is in the site_tmplvar_contentvalues table. If it is your first tv ever it will be 1. Enter this value for $tempid. Then add this snippet to your homepage and promote some documents. You are set. If you have any text in the summary field it will be displayed instead of the shortened content by default (very handy if you experience formatting issues)
//BEGIN CONFIG
$lentoshow = 425; // Number of characters to display of the document
$nr = 5; // Number of documents to show
$tempid = 1; // ID of checkbox tv
$showcategory = true; //Set to true to disply the parent document's title otherwise set to false
//END CONFIG
$tbl = "".$this->dbConfig['table_prefix']."site_tmplvar_contentvalues";
$tbl2 = "".$this->dbConfig['table_prefix']."site_content";
$ftbl = $this->dbConfig['dbase'].".".$this->dbConfig['table_prefix']."site_tmplvar_contentvalues";
$ftbl2 = $this->dbConfig['dbase'].".".$this->dbConfig['table_prefix']."site_content";
$sql = "SELECT $tbl2.id, pagetitle, description, content, introtext, createdon, parent FROM $ftbl,$ftbl2 WHERE published=1 AND deleted=0 AND tmplvarid=$tempid AND value='Yes' AND $tbl.contentid = $tbl2.id ORDER BY createdon DESC";
$rs = $modx->dbQuery($sql);
$limit = $modx->recordCount($rs);
if($limit<1) {
$output = "No documents found.<br />";
}
$nrvalue = $nr<$limit ? $nr : $limit;
$extendvalue = isset($extend);
if ($extendvalue == TRUE){$nrvalue = $limit; $lentoshow = 0;}
for ($x = 0; $x < $nrvalue; $x++) {
$resource = $modx->fetchRow($rs);
// show summary
if(strlen($resource['introtext'])>0) {
if ($extendvalue != TRUE){ $rest = $resource['introtext'];
if(strlen($resource['content'])>0) $rest .= "...<br /><br /><a href='[~".$resource['id']."~]'>More on this story ></a>"; }
} else if(strlen($resource['content'])>$lentoshow) {
// strip the content
if ($extendvalue != TRUE){
$rest = substr($resource['content'], 0, $lentoshow);
$rest .= "...<br /><br /><a href='[~".$resource['id']."~]'>More on this story ></a>"; }
} else {
if ($extendvalue != TRUE){ $rest = $resource['content']; }
}
$pid = $resource['parent'];
$parent = $modx->getPageInfo($pid);
//FORMAT HERE
if ($extendvalue == TRUE){
$output .= "<div class='contentbox'><div class='newsbg'><b><a href='[~".$resource['id']."~]'>".$resource['pagetitle']."</a></b> --- <i>".strftime("%A, %B %d, %Y", $resource['createdon'])."</i></div><br /></div><br />";
}
else {
$output .= "<div class='contentbox'><div class='newsbg'><b>";
if ($showcategory == true) {
$output .= "<a href='[~".$parent['id']."~]'>".$parent['pagetitle']."</a> »";
}
$output .= "".$resource['pagetitle']."</b> --- <i>".strftime("%A, %B %d, %Y", $resource['createdon'])."</i></div><br />".$rest."</div><br />";
}
//END FORMAT
}
if ($extendvalue != TRUE){
$output .= "<div style='text-align:center;'><a href='[~50~]'>Archive</a></div>";}
return $output;