You get a bonus - 1 coin for daily activity. Now you have 1 coin

How to make an automatic news sitemap in CMS Made Simple

Practice




How to make an automatic sitemap for news in CMS Made Simple
I installed the modules
CGExtensions
and
SiteMapMadeSimple

but it only generates a sitemap for the site's pages and menu, but I need a sitemap for all published articles

add this function to the file

function GetAllNewsUrl()
{
$gCms = cmsms();
$results = $res = $params = array();
$detailpage = 23;

$db = $this->GetDb();
$query = "SELECT news_title,news_url,news_id,modified_date FROM " .
cms_db_prefix() . "module_news WHERE status = 'published'";

$result = $db->Execute($query);

while ($result && !$result->EOF)
{


$aliased_title = munge_string_to_url($result->fields['news_title']);
$prettyurl = 'news/' . $result->fields['news_id'] . '/' . $detailpage . "/$aliased_title" .
$detailtemplate;


$res['prettyurl'] = $prettyurl;
$res['id'] = $result->fields['news_id'];
$res['time'] = $result->fields['modified_date'];

$parms = array();
$parms['articleid'] = $result->fields['news_id'];

$res['url'] = $this->CreateLink('cntnt01', 'detail', $detailpage, '', $parms, '', true, false,
'', true, $prettyurl);
$results[] = $res;


$result->MoveNext();
}


return $results;
}



and inside the function

function GenerateSiteMap(&$params)
{



after
$output[] = $obj;
}


add this loop

$news = $this->GetAllNewsUrl();

foreach ($news as $onecontent)
{


$obj = new StdClass();

$priority = 0.7;

$obj->priority = number_format($priority, 1, '.', '');
$obj->encoded_url = cms_htmlentities($onecontent['url']);
$obj->cachable = false;
$obj->child_count = 0;
$obj->hierarchy = '';
$obj->date = trim($db->DbTimeStamp($onecontent['time']), "'");
$obj->url = $onecontent['url'];
$obj->id = $onecontent['id'];
$obj->type = 'news';

$obj->frequency = $this->GetPreference('change_frequency', 'auto');
if ($obj->frequency == 'auto')
{
$obj->frequency = 'hourly';
if ($mdate < $onedayago)
$obj->frequency = 'daily';
if ($mdate < $oneweekago)
$obj->frequency = 'weekly';
if ($mdate < $onemonthago)
$obj->frequency = 'monthly';
if ($mdate < $oneyearago)
$obj->frequency = 'yearly';
}


$output[] = $obj;
}

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Running server side scripts using PHP as an example (LAMP)"

Terms: Running server side scripts using PHP as an example (LAMP)