• [Snippet] homepagedisplay #

  • MARKSVIRTUALDESK Reply #1, 6 years, 6 months ago

    Reply
    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;
    


  • Zaigham (aka zi) Reply #2, 6 years, 6 months ago

    Reply
    Thanks for nice Snippet !!

    Regards,

    zi


  • MARKSVIRTUALDESK Reply #3, 6 years, 6 months ago

    Reply
    Quote from: (-zi-) at Jul 25, 2005, 02:10 PM
    Thanks for nice Snippet !!

    Regards,

    zi

    Your welcome


  • Dimmy Reply #4, 6 years, 6 months ago

    Reply
    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?


  • MARKSVIRTUALDESK Reply #5, 6 years, 6 months ago

    Reply
    Quote from: Dimmy at Jul 26, 2005, 02: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, 02:29 AM
    if this is the case its superb was looking for a snippet like that.
    Thanks
    Quote from: Dimmy at Jul 26, 2005, 02: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.



  • MARKSVIRTUALDESK Reply #6, 6 years, 6 months ago

    Reply
    How did it work for you Dimmy?


  • MARKSVIRTUALDESK Reply #7, 6 years, 5 months ago

    Reply
    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!


  • Dimmy Reply #8, 6 years ago

    Reply
    Quote from: Mark at Jul 28, 2005, 10:28 PM
    How did it work for you Dimmy?

    Worked great I use it on www.eljakim.nu for the news item in the lamplight


  • wendy Reply #9, 6 years ago

    Reply
    This is a cool snippet. Any thought in integrating this one with tv name, instead of tv id?


  • banzai Reply #10, 6 years ago

    Reply
    Great snippet, but i think now you can use newlisting tvars filter.