Display the content of the most recently created page?

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Display the content of the most recently created page?

Post by Dr.CSS »

If you make a new page with specific content and then use something to pull that content into the 'Home' page wouldn't that be duplicate content to search bots like google..?

There isn't any way to do this built into the core but you can use a module to pull it, CGSimpleSmarty comes to mind but if it is a new page every time then you would have to change the {tag} every time...

I think it would be better to use a module like News to do this {news number='1'} will show the newest News article all the time automatically...
User avatar
rotezecke
Power Poster
Power Poster
Posts: 411
Joined: Fri Apr 18, 2008 9:34 pm

Re: Display the content of the most recently created page?

Post by rotezecke »

i agree with the Dr, but for the sake of the exercise:

create a UDT "latestContent"

Code: Select all

$db = cmsms()->GetDb(); 
$smarty = cmsms()->GetSmarty();

//find latest content
$query = 'SELECT content_alias FROM '.cms_db_prefix().'content WHERE type = "content" AND active="1" ORDER BY modified_date DESC Limit 1';

$result1 = $db->Execute($query);
while ($result1 && $row = $result1->FetchRow()) {
 $latestContent = $row['content_alias'];
}
//assign smarty variable
$smarty->assign('smartyLatestContent', $latestContent); 
Then put this in your template:

Code: Select all

{latestContent}
{$cgsimple->get_page_content("$smartyLatestContent",'','evalMe')}
{eval var=$evalMe}
Requirements:
1) CGSimpleSmarty

Limitations:
1) above code assumes there's only one content block on the page with the last modified time stamp
2) if you put the smarty code in a content area instead of a template you'll set the last_modified timestamp of that page and when looking at it you will get some sort of loop. i didnt try this but it cannot be good.

EDIT: I misread your question. the above uses modified date instead of creation date. change sql. ... ORDER BY create_date DESC LIMIT 1
in which case it should also work in content section as long as its not the last page created.
Post Reply

Return to “CMSMS Core”