We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18397
    • 3,250 Posts
    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;
    
      • 33337
      • 3,975 Posts
      Thanks for nice Snippet !!

      Regards,

      zi
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 18397
        • 3,250 Posts
        Quote from: (-zi-) at Jul 25, 2005, 07:10 PM

        Thanks for nice Snippet !!

        Regards,

        zi

        Your welcome
          • 7455
          • 2,204 Posts
          I am not realy sure what this does...
          Is it like a news thing but than you can select by a TV what docs it wil show?

          if this is the case its superb was looking for a snippet like that.
          if not pleas explain and maybe you have a demo url?
            follow me on twitter: @dimmy01
            • 18397
            • 3,250 Posts
            Quote from: Dimmy at Jul 26, 2005, 07:29 AM

            Is it like a news thing but than you can select by a TV what docs it wil show?
            Yes
            Quote from: Dimmy at Jul 26, 2005, 07:29 AM

            if this is the case its superb was looking for a snippet like that.
            Thanks
            Quote from: Dimmy at Jul 26, 2005, 07:29 AM
            maybe you have a demo url?
            I am unsure as how to create a demo since it could be a security risk, but I could post screenshots if people would like.

              • 18397
              • 3,250 Posts
              How did it work for you Dimmy?
                • 18397
                • 3,250 Posts
                I have updated the first post with a newer version with several fixes and improvements.

                Could someone advise on how to allow a user to enter a tv name instead of its id for use with this snippet?

                Thanks in advance!
                  • 7455
                  • 2,204 Posts
                  Quote from: Mark at Jul 29, 2005, 03:28 AM

                  How did it work for you Dimmy?

                  Worked great I use it on www.eljakim.nu for the news item in the lamplight
                    follow me on twitter: @dimmy01
                    • 32241
                    • 1,495 Posts
                    This is a cool snippet. Any thought in integrating this one with tv name, instead of tv id? wink
                      Wendy Novianto
                      [font=Verdana]PT DJAMOER Technology Media
                      [font=Verdana]Xituz Media
                      • 2762
                      • 1,198 Posts
                      Great snippet, but i think now you can use newlisting tvars filter.
                        Free MODx Graphic resources and Templates www.tattoocms.it
                        -----------------------------------------------------

                        MODx IT  www.modx.it
                        -----------------------------------------------------

                        bubuna.com - Web & Multimedia Design