If you own a website then one very common problem that you might come across is that some of your webpages might not show up in the search results. In such a case, most of us believe that the webpage does not have any links to them on the website. But unless the search engines have banned that web page, there are very less chances of any particular webpage not having links to it on the website. And in such a scenario, you are required to provide a proper navigation structure for your users, but that might not be a feasible option, especially when your website is having lot of content
. Web pages of any website can be hidden due to any reason. Creating a sitemap is the most workable solution to reduce the amount of hidden web pages not found in the search results of your site. Hearing this most of you will be thinking of searching of some website sitemap generator that will generate a sitemap for your site. But that might not be the best way. No one else can know your website better than you, also it is you who has the access to all the files of your website. Therefore, it is you who can create the best website sitemap for your users and the search engines.
Sitemaps are preferably written in XML format, but it is not necessary for you to write XML code for each and every web page of your website manually. A better way is to build a XML sitemap together with PHP.
<?php<br /> header("Content-Type: application/xml; charset=utf-8");<br /> echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;<br /> echo'<urlsetxmlns="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">' .PHP_EOL;<br /> <br /> function urlElement($url) {<br /> echo '<url>'.PHP_EOL;<br /> echo '<loc>'.$url.'</loc>'. PHP_EOL;<br /> echo '<changefreq>weekly</changefreq>'.PHP_EOL;<br /> echo '</url>'.PHP_EOL;<br /> }<br /> <br /> urlElement('http://www.programming.com/services/default-text-generator/');<br /> urlElement('http://www.programming.com/tests/practice/');<br /> urlElement('http://www.programming.com/tests/practice/HTML/');<br /> echo '</urlset>';<br /> ?>
In the above given example, we instantly send a header to inform the browser that the type of the content that is entered is XML and that it should render the page as XML. Then, we will set up the version information and where the schema is located, but you can merely copy all of that. Now, the interesting part is our urlElement function that takes the url as an argument and creates a url element in our sitemap. In the above example only changefreq and loc are used as a child element of url but, if you want then you can also use lastmod and priority to your url elements. But both of the elements can turn out to be useless, as search engines determine these elements on their own.
In case you have a dynamic website having content stored in a database, then you can create a function that loops through each url to that content. For this all you need to do is to place your content’s url inside the urlElement call during each loop.
To create dynamic sitemaps feel free to modify and build XML sitemap with the PHP code written as above.
About Author:
Celin is web developer and a team member of Xicom – Custom PHP Development team provides a talented PHP Developers For Hirefor all PHP Development Frameworks.