• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.

How to generate a Sitemap.xml file + Cron Job - (Chevereto).

maxdome

Chevereto Member
Hi, I wrote this script to generate a Cheverote sitemap.xml file.
Its executed via a cron job and seems to be working perfectly.

Step-1: This script will generate a sitemap.xml file with existing category names fron Your Chevereto.
PHP:
<?php
if (!defined('BASEPATH')) exit('This script is read by the Cron System. The Browser access is blocked. ');

$localdb="localhost";         // Your Hostname (default is localhost)
$userdb="username";         // Your Database Username
$passdb="password";         // Your Database Password
$mysqldb="database";        // Your Database Name

$WebUrl="http://www.mydomain.com";  // Your Cheverote Domain without(/)
$catfolder="category";      // Do not change anything here

$dbconection = mysql_connect($localdb, $userdb, $passdb );
mysql_select_db($mysqldb, $dbconection);

$sqlget = "SELECT category_url_key FROM chv_categories";
$resuldata = mysql_query($sqlget,$dbconection);
$priority = '0.7';
$changefreq = 'weekly';
$datem = date("Y-m-d");

$codtgetdata='<?xml version="1.0" encoding="iso-8859-1"?>
<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">';


while ($rowdata = mysql_fetch_array($resuldata)){
$codtgetdata .='<url>
<loc>'.$WebUrl.'/'.$catfolder.'/'.$rowdata["category_url_key"].'</loc>
<lastmod>'.$datem.'</lastmod>
<changefreq>'.$changefreq.'</changefreq>
<priority>'.$priority.'</priority>
</url>';
}
$codtgetdata .='</urlset> ';

$path = "sitemap.xml";
$modo = "w+";

if ($fpen=fopen($path,$modo)){
   fwrite ($fpen,$codtgetdata);
   echo "<p><b>Sitemap successfuly created and saved to sitemap.xml!</b>";
}else{
   echo "<p><b>There has been a problem and the file has not been created.</b>";
}
mysql_free_result($resuldata);
mysql_close($dbconection);
?>

Step-2: Create a new file and save it as sitemap.php

Step-3: Upload a sitemap.php file in your Cheverote home web - (FTP)

Step-4: For the Cron Job..
ROOT: crontab -e
USER: crontab -u USER -e
add this script:
30 12 * * * curl http://www.yourdomain.com/sitemap.php > /dev/null 2>&1
This cron job start the script every day 12:30 h. You can change the time to any time you want.
Remember to change the domain www.yourdomain.com with your Cheverote Domain.

If you want to test the script without the Cron Job, disable this line in the php:
PHP:
//if (!defined('BASEPATH')) exit('This script is read by the Cron System. The Browser access is blocked. ');
and enter this URL in your Browser: http://www.yourdomain.com/sitemap.php

Step-5: Check the FTP and see a file created with the name sitemap.xml

*You can add more options for sitemap.php, for example Users Public Albums

DEMO: https://zupics.com/sitemap.xml

----------------------------------------------------------------------------------------------------------------------
PLEASE READ THIS:
Sitemap.xml, on the other hand, is a file where you list all of the pages of your website.
It tells the search engines – Google, Bing, Yahoo and others about the pages, images, videos and grouping of your site content.
Search engine web crawlers such as Googlebot read the sitemap.xml and indexed your site to their search directories.

Create an XML sitemap that can be submitted to Google, Bing, Yahoo and other search engines to help them crawl your website better.

How do you submit sitemap.xml to the search engines?

Due to time limitation, I will limit my response to submitting sitemap.xml to only Google.

Submitting your sitemap.xml to Google Webmaster Tools

  1. Register for Google Webmaster Tools
  2. On your Webmaster Tools home page, register and select your website.
  3. In the left sidebar, click Site configuration and then Sitemaps.
  4. Click the Add/Test Sitemap button in the top right.
  5. Enter sitemap.xml into the text box that appears.
  6. Click Submit Sitemap.
  7. Click “Refresh”.
In most cases, when a sitemap.xml is correctly created and submitted to the search engines, that site ‘organic search’ increases up to 1,000%.
This in return creates a significant impact on a business sales and bottom line.

If your business’ website doesn’t have a sitemap.xml, you’re most likely leaving money on the table.

-----------------------------------------------------------------------------------------------------------------------

Good Luck

If you liked my idea, please click the "like" button :)

Best Regards:
Gio
 
Last edited:
I am getting these errors and site map is almost blank.

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in D:\website\sitemap.php on line 12

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\website\sitemap.php on line 29
Sitemap successfuly created and saved to sitemap.xml!
Warning
: mysql_free_result() expects parameter 1 to be resource, boolean given in D:\website\sitemap.php on line 48

Update:
Found error to be "SELECT category_url_key FROM chv_categoriesResource id #3Table 'mkerala_chv229.chv_categories' doesn't exist"

Since my site don't use categories I can't use this.

Update 2: Just realized the sitemap is only for category URLs. I thought it would generate link to each image uploaded to site.
 
Last edited:
Please don't use mysql_connect. It's deprecated, even mysqli is too old -> use PDO.
 
Just to collaborate here, is easier if you work with the bundled script libraries like CHV\DB
 
i am getting the below error. my database details are correct


Warning: mysql_connect(): Access denied for user 'user_user'@'localhost' (using password: YES) in /home/user/public_html/sitemap.php on line 12

Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in /home/user/public_html/sitemap.php on line 13

Warning: mysql_query() expects parameter 2 to be resource, boolean given in /home/user/public_html/sitemap.php on line 16

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/user/public_html/sitemap.php on line 29
Sitemap successfuly created and saved to sitemap.xml!
Warning: mysql_free_result() expects parameter 1 to be resource, null given in /home/user/public_html/sitemap.php on line 48

Warning: mysql_close() expects parameter 1 to be resource, boolean given in /home/user/public_html/sitemap.php on line 49
 
Your user credentials are not correct. You could use my improved script which use the same credentials as your chevereto installation.
 
Back
Top