Topic: [Snippet] homepagedisplay  (Read 9203 times)

Pages: [1]   Go Down

#1: 25-Jul-2005, 01:58 PM

Emeritus
Mark
Posts: 3,250

Ditto Developer

WWW
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:

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> &raquo;";
}

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


* screenshot.JPG (22.35 KB, 640x229 - viewed 1826 times.)
« Last Edit: 5-Sep-2005, 09:25 PM by Mark »

#2: 25-Jul-2005, 02:10 PM

Administrator

zi
MODx Special Forces /
Posts: 3,555

May Peace Be On You

WWW
Thanks for nice Snippet !!

Regards,

zi

#3: 25-Jul-2005, 02:15 PM

Emeritus
Mark
Posts: 3,250

Ditto Developer

WWW
Thanks for nice Snippet !!

Regards,

zi

Your welcome

#4: 26-Jul-2005, 02:29 AM

Testers

Dimmy
Posts: 2,001

Я не говорю по-русски 私は日本語を話さない

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

#5: 26-Jul-2005, 01:17 PM

Emeritus
Mark
Posts: 3,250

Ditto Developer

WWW
Is it like a news thing but than you can select by a TV what docs it wil show?
Yes
if this is the case its superb was looking for a snippet like that.
Thanks
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.

#6: 28-Jul-2005, 10:28 PM

Emeritus
Mark
Posts: 3,250

Ditto Developer

WWW
How did it work for you Dimmy?

#7: 5-Sep-2005, 09:13 PM

Emeritus
Mark
Posts: 3,250

Ditto Developer

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

#8: 6-Feb-2006, 04:32 PM

Testers

Dimmy
Posts: 2,001

Я не говорю по-русски 私は日本語を話さない

WWW
How did it work for you Dimmy?

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

#9: 6-Feb-2006, 05:08 PM

Emeritus
Djamoer
Posts: 1,495

No one can limit a man other than the man himself.

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

#10: 6-Feb-2006, 05:27 PM

Testers

banzai
Posts: 880

MODx Italia

WWW
Great snippet, but i think now you can use newlisting tvars filter.
« Last Edit: 6-Feb-2006, 05:29 PM by banzai »
MODx Websites Showcase 
Add your site to www.modx.it!
-----------------------------------------------------
FREE MODx Templates
www.tattoocms.it
-----------------------------------------------------
VIDEO: whats new in MODx 0.9.5   | VIDEO: MODx PHP Application Framework  |  modx Revolution  

bubuna.com - Web & Multimedia Design

#11: 6-Feb-2006, 07:35 PM

Emeritus
Mark
Posts: 3,250

Ditto Developer

WWW
Yes, NewsListing in the snippet to use now... Thanks to multiple levels and tv filters this snippet is now obsolete (hey I'm deprecating one of my own snippets and sending users to another of my snippets!).

#12: 7-Feb-2006, 02:36 AM

Coding Team

sottwell
Posts: 10,529

WWW
But does it have a feature for displaying a random selection?
sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html

#13: 7-Feb-2006, 03:15 AM

Testers

Dimmy
Posts: 2,001

Я не говорю по-русски 私は日本語を話さない

WWW
It still worked nice for me tho hehe
I edited the snippet to have classes and show not only the introtext but also the pagetitle and have a nother class for the read more part

#14: 7-Feb-2006, 08:20 AM

Emeritus
Djamoer
Posts: 1,495

No one can limit a man other than the man himself.

WWW
I guess, I will put down the snippet for the sake of the author itself.
Pages: [1]   Go Up
0 Members and 1 Guest are viewing this topic.