Skip to content
General Revolution Evolution Add-ons International
Login | Register | MODX.com
MODX Open Source Content Management System, Framework, Platform and More.
Find a Partner | Hosts + SaaS | Jobs | Donate
  • RegisterSign Up with the MODX Community
  • LoginUse Your MODX.com Account
  • MODX Community Forums
  • Add-ons
  • Module, Plugin & Snippet Usage
  •  
  • <
  • 1
  • 2
  • >
  • [Snippet] homepagedisplay #

  • 18397
    3,250
    Documentation TRAC (Bugtracker) Forum How to get help
    User Wiki Credits SVN Server Ditto HQ
    Stable Download Development Download

    MARKSVIRTUALDESK Reply #1, 6 years, 10 months ago

    Reply
    • Link to this post#1
    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,901
    - MODX Special Forces
    Share and explore websites made in MODx by Zaigham's Web | Tweet @zaigham | Resource Center


    MODx Current | MODx on Git! | BUGS! | RTFM (Read the Fully awesome Manuals)

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

    Reply
    • Link to this post#2
    Thanks for nice Snippet !!

    Regards,

    zi


  • 18397
    3,250
    Documentation TRAC (Bugtracker) Forum How to get help
    User Wiki Credits SVN Server Ditto HQ
    Stable Download Development Download

    MARKSVIRTUALDESK Reply #3, 6 years, 10 months ago

    Reply
    • Link to this post#3
    Quote from: (-zi-) at Jul 25, 2005, 02:10 PM
    Thanks for nice Snippet !!

    Regards,

    zi

    Your welcome


  • 7455
    2,190
    follow me on twitter: @dimmy01

    Dimmy Reply #4, 6 years, 9 months ago

    Reply
    • Link to this post#4
    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?


  • 18397
    3,250
    Documentation TRAC (Bugtracker) Forum How to get help
    User Wiki Credits SVN Server Ditto HQ
    Stable Download Development Download

    MARKSVIRTUALDESK Reply #5, 6 years, 9 months ago

    Reply
    • Link to this post#5
    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.



  • 18397
    3,250
    Documentation TRAC (Bugtracker) Forum How to get help
    User Wiki Credits SVN Server Ditto HQ
    Stable Download Development Download

    MARKSVIRTUALDESK Reply #6, 6 years, 9 months ago

    Reply
    • Link to this post#6
    How did it work for you Dimmy?


  • 18397
    3,250
    Documentation TRAC (Bugtracker) Forum How to get help
    User Wiki Credits SVN Server Ditto HQ
    Stable Download Development Download

    MARKSVIRTUALDESK Reply #7, 6 years, 8 months ago

    Reply
    • Link to this post#7
    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,190
    follow me on twitter: @dimmy01

    Dimmy Reply #8, 6 years, 3 months ago

    Reply
    • Link to this post#8
    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


  • 32241
    1,495
    Wendy Novianto
    PT DJAMOER Technology Media
    Xituz Media

    wendy Reply #9, 6 years, 3 months ago

    Reply
    • Link to this post#9
    This is a cool snippet. Any thought in integrating this one with tv name, instead of tv id?


  • 2762
    894
    MODx Websites Showcase 
    Add your site to www.modx.it!
    -----------------------------------------------------
    FREE MODx Templates
    www.tattoocms.it
    -----------------------------------------------------

    bubuna.com - Web & Multimedia Design

    banzai Reply #10, 6 years, 3 months ago

    Reply
    • Link to this post#10
    Great snippet, but i think now you can use newlisting tvars filter.


  • <
  • 1
  • 2
  • >



Actions

Login to Post

Other Support Options

To file a bug or make a feature request visit our issue tracker, or you can also purchase commercial support.

Love MODX?

If you build sites for a living with MODX or just love using it, why not give back?

Information

Posted in this thread:
Dimmy, MARKSVIRTUALDESK, banzai, sottwell, wendy, zaigham

 
Back to Top

MODX Global HQ

1333 N Stemmons Fwy, Ste 110
Dallas, TX 75207
United States

+1 (469) 777-MODX (6639)

The MODX Company

  • Contact
  • Media Center
  • Careers at MODX
  • Wall of Fame
  • The MODX Blog

Sponsors

SoftLayer Firehost: Secure Cloud Hosting

Stay Connected

Read our previous email newsletters.

Twitter Facebook Google+ LinkedIn github Feeds

Privacy Policy | Terms of Service | Pixels by AKTA Web Studio© 2005-2012 MODX. All rights reserved. Trademark Policy