ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Tutorial: How to make a Google News Sitemap

March 28, 2009 12:34pm

Subscribe [8]
  • #1 / Mar 28, 2009 12:34pm

    11Media

    157 posts

    Hi,

    If your website has been accepted onto Google news, you’d need to create a special new Sitemap for it. I’ve just finished mine so I thought I’d share how I did it and hopefully someone will find it useful. There are different requirements to an ordinary Sitemap one of which being google only indexes the last 3 days of news and would give you errors in your Google webmaster tools Sitemap if you have entries older than this.

    Note:
    You will need php turned on and the PHP parsing set to Input

    Here’s how it’s done.
    1. Create a new template in the root/top level of your website called news-sitemap.

    Top level being (depending on your EE setup):
    yoursite.com/index.php/news-sitemap/
    or
    yoursite.com/news-sitemap/
    or
    yoursite.com/site/index.php/news-sitemap/
    etc..

    2. Add the following code:

    <?xml version="1.0" encoding="UTF-8"?>
    <urlset >
    <?php
    global $LOC;
    $start_time = $LOC->decode_date('%Y-%m-%d %H:%i', $LOC->now - 259200);
    ?>
    
    {exp:weblog:entries weblog=(change_this)" sort="desc" start_on="<?php echo $start_time; ?>" disable="pagination|trackbacks" rdf="off" dynamic="off"}
    
      <url>
        <loc>{path=}stories/{url_title}/</loc>
        1.0</priority>
        <news:news>
          <news:publication_date>{exp:stats}{entry_date format="{DATE_W3C}"}{/exp:stats}</news:publication_date>
          <news:keywords>{News_Keywords}</news:keywords>
        </news:news>
      </url>
    {/exp:weblog:entries}
    </urlset>

    Note:
    This is how I pulled the url to my news, you will need to change this to match your path/setup.

    <loc>{path=}stories/{url_title}/</loc>

    I have a custom weblog field called {News_Keywords} - allowing me to add comma separated keywords on each entry you can do the same or if you have a module such as LG Better Meta, you may be able to use the tags to pull in the keywords automatically.

    <news:keywords>{News_Keywords}</news:keywords>

    3. Sign into your Google Webmaster Tools Account
    http://www.google.com/webmasters/tools/

    Add submit your news sitemap.

    Hope that helps! 😊

  • #2 / Mar 29, 2009 2:52am

    Doxey

    8 posts

    This is very cool. Thank you.  I will give it try.
    Dox

  • #3 / Jun 08, 2009 2:59pm

    APGWest

    295 posts

    Thanks for this 11Media!  Here’s a few tweaks that I made to get this to validate with Google.

    <?xml version="1.0" encoding="UTF-8"?>
    <urlset >
    <?php
    global $LOC;
    $start_time = $LOC->decode_date('%Y-%m-%d %H:%i', $LOC->now - 259200);
    ?>
    {exp:weblog:entries weblog="_____name_of_your_weblog_____" sort="desc" start_on="<?php echo $start_time; ?>" disable="pagination|trackbacks" rdf="off" dynamic="off"}
      <url>
        <loc>_____http://www.website.com/home/article/_____{url_title}/</loc>
        1.0</priority>
        <news:news>
          <news:publication_date>{exp:stats}{entry_date format="{DATE_W3C}"}{/exp:stats}</news:publication_date>
          <news:keywords>_____your_keywords_field_name_here_(optional)_____</news:keywords>
        </news:news>
      </url>
    {/exp:weblog:entries}
    </urlset>

    Basically, the urlset needed the additional info so Google knows it’s a news sitemap.  It looks like you also left off a ” on the weblog= parameter.  Yeah, I know - picky picky! :p I also noticed keywords were optional but I’d leave the tags in there if you opt to leave it blank (i.e. <news:keywords></news:keywords>).

  • #4 / Jun 09, 2009 11:37am

    Charles Boudinot

    87 posts

    I think it would be great to add this to the EE Wiki.

  • #5 / Jun 09, 2009 12:47pm

    APGWest

    295 posts

    Hmm, it cut out the urlset info on my code, which means you probably had it right, 11Media.  Let’s see if I can get it to display right…

    <urlset x_mlns="http://www.sitemaps.org/schemas/sitemap/0.9" x_mlns:news="http://www.google.com/schemas/sitemap-news/0.9">

    Remove the underscores and you’re good to go.

  • #6 / Jul 09, 2009 7:30pm

    mirkob

    74 posts

    Is it possible to create the sitemap without specify any weblog?
    Is any {variable} that figures out the full path of a entry?

    <?xml version="1.0" encoding="UTF-8"?>
    <urlset >
        {exp:weblog:entries
       
          disable="categories|member_data|pagination|trackbacks"
          dynamic="off"
          rdf="off"
          status="open"
        }
        <url>
          <loc>{variable}</loc>
          <lastmod>{edit_date format="%Y-%m-%d"}</lastmod>
          <changefreq>weekly</changefreq>
          0.5</priority>
        </url>
       {/exp:weblog:entries}
    
    </urlset>
  • #7 / Apr 06, 2010 4:22pm

    James Smith

    259 posts

    Thanks 11Media, this was very handy and saved me having to think. 😊

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases