Recent Post

Dear reader, this blog has been moved to here

Friday, 26 July 2013

Sitemap for SMF (acceptable for Google Webmasters)



Hi all,

A former mod of Sitemap for SMF does not get accepted by Google Webmasters Site when I want to submit it, because it has no acceptable file format for spiders to access. Its something like this http://yoursite.com/index.php?action=kitsitemap;xml

Now a coded a piece of PHP to create a sitemap containing boards and topic links only and acceptable by Google, just copy the below code and save as sitemap.php

  1. <?php
  2. /*
  3. Sitemap for SMF written by DON JAJO
  4. http://2netlodge.com
  5. */
  6. $dbhost = "";//your database host, usually "localhost" in many servers
  7. $dbname = "";// your SMF database name
  8. $dbuser = "";// your SMF database user or username
  9. $dbpwd = "";// your SMF database password
  10. $siteurl = "http://yoursite.com/";// your site URL with trailing slash (eg http://yoursite.com/)
  11. //Connection to database done!
  12. $connect = mysql_connect($dbhost,$dbuser,$dbpwd)or die(mysql_error());
  13. //I selected database name
  14. mysql_select_db($dbname);
  15. //Configuring headers
  16. header("Content-type: text/xml");
  17. echo<?xml version=1.0 encoding=UTF-8?>';
  18. echo' <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
  19. ?>
  20. <?php
  21. //querying for board ids in the database
  22. $boards = mysql_query("select * from smf_boards")or die(mysql_error());
  23. while($row = mysql_fetch_array($boards))
  24. {
  25. $boardid = $row['id_board'];
  26. //Outputing
  27. ?>
  28. <url>
  29. <loc><?=$siteurl?>index.php?board=<?=$boardid?>.0</loc>
  30. </url>
  31. <?php
  32. }
  33. //querying for topic ids in the database
  34. $topics = mysql_query("select * from smf_topics")or die(mysql_error());
  35. while($row2 = mysql_fetch_array($topics))
  36. {
  37. $topicid = $row2['id_topic'];
  38. //Outputing
  39. ?>
  40. <url>
  41. <loc><?=$siteurl?>index.php?topic=<?=$topicid?>.0</loc>
  42. </url>
  43. <?php
  44. }
  45. ?>
  46. </urlset>

Edit the Mysql details and save
NOTE: If your table prefix is not smf_ please change it from the query

I don't know how to create SMF mod, I would have created a mod for it

Run http://yoursite.com/sitemap.php
Hope it helps! :)

Email Newsletter



Smiley :)
:D
:)
:[
;)
:D
:O
(6)
(A)
:'(
:|
:o)
8)
(K)
(M)

No comments:

Post a Comment