Friday, September 2, 2011

Tip 11: Making Simple Sitemap for Article Object



Search Engine like Google, Yahoo, Bing, and others use RSS feed for their sitemap to crawl or index a website . TikiWIki has this feature by enabling the RSS feed through the administrator menu. Subcribing the RSS Feed can make the search engine to crawl or index the website when any new information arrived. If you feel that the RSS Feed provided by TikiWIki is not enough, you can make a sitemap using this program below.


<?php
//identify host and its directory, if any
require_once ('tiki-setup.php');
include_once ('lib/articles/artlib.php');
global $smarty, $tikilib;
$foo = parse_url($_SERVER["REQUEST_URI"]);
$parts = explode('/', $foo['path']);
if (count($parts) > 1) unset ($parts[count($parts) - 1]);
$mail_machine_raw = $tikilib->httpPrefix( true ) . implode('/', $parts) . '/';

header("Content-type: text/xml");

//connect to database
require 'type you location of local.php here';
$connectionId = mysql_connect($host_tiki, $user_tiki, $pass_tiki) or die("Could not connect to host.");
mysql_select_db($dbs_tiki, $connectionId) or die("Could not find database.");



//connect to the table tiki_articles

$query = "SELECT * FROM tiki_articles ORDER BY created DESC";
$resultID = mysql_query($query, $connectionId) or die("Data not found.");

//xml
$xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; //start create xml
$xml_output .= "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
$xml_output .= "\t<url>\n";
if ($row['publishDate'] > $row['created']) {
$lastmod=$row['publishDate'];
} else {
$lastmod=$row['created'];
}
include_once('tiki-sefurl.php');
$article = $mail_machine_raw . filter_out_sefurl('tiki-read_article.php?articleId=' . $row['articleId'], $smarty, 'article', $row['title']);
$xml_output .= "\t\t<loc>" . $article . "</loc>\n"; //identify url location
$xml_output .= "\t\t<lastmod>" . gmdate("Y-m-d",$lastmod) . "</lastmod>\n"; //identify last modification
$xml_output .= "\t\t<changefreq>" . "daily" . "</changefreq>\n";
$xml_output .= "\t</url>\n";
}
$xml_output .= "</urlset>";
echo $xml_output;
?>

Save the above scripts to sitemap1.php. If you have already registered your website to Google, Yahoo, and Bing, then you can add to subscribe  the sitemap1.php to them.

1 comment:

  1. Link does not appear well.



    http://www.portal-spiritual.eu/tiki-read_article.php?articleId=182-article&

    2015-03-20
    daily


    http://www.portal-spiritual.eu/

    ReplyDelete