Creating an XML sitemap with PHP

后端 未结 3 1583
庸人自扰
庸人自扰 2020-12-08 08:23

I\'m trying to create a sitemap that will automatically update. I\'ve done something similiar with my RSS feed, but this sitemap refuses to work. You can view it live at htt

3条回答
  •  春和景丽
    2020-12-08 08:25

    I've used William's code (thanks) and with a few small modifications it worked for me.

    I think the line:

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

    should be the second line after the top

    Incidentally, just a small point to anyone else that copies it, but there is a single space character before the in the first line - if you inadvertantly copy it as I did, you will spend a bit of time trying to figure out why the code won't work for you!

    I had to tweak the MySql select statement a little bit too.

    Finally, in the output, I have used a variable $domain so that this piece of code can be used as a template without the need to think about it (provided you use the same table name each time). The variabe is added to the connectdb.php file which is included to connect to the database.

    Here is my working version of the William's code:

    ';
    include 'includes/connectdb.php';
    ?>
    
    
    
        
            http://www.DOMAIN.co.uk/
            1.00
        
    
        
        
            http://www./
            monthly
            0.5
        
    
     
    
    
    

提交回复
热议问题