Google News Extension

Discuss PivotX 2.0.x extensions here, and view extensions that are available for download.

Google News Extension

Postby cablock » Mon Jul 11, 2011 9:43 am

Has anyone developed a dynamic XML map that lists weblog entries? I already publish to Google news with another site and it requires a particular format as well as (crucially) data lookup to keep it current.

The syntax is along the lines of:

<url>
<loc>(get link)</loc>
<n:news>
<n:publication>
<n:name>My site</n:name>
<n:language>en</n:language>
</n:publication>
<n:genres>UserGenerated</n:genres>
<n:title><%=enc((rs("headline")))%></n:title>
<n:publication_date></n:publication_date>
<n:keywords></n:keywords>
</n:news>
</url>

I'm really struggling to resolve this. Is there a dynamic extension I've missed that might help me generate a weblog map or something close?
cablock
 
Posts: 7
Joined: Mon Jul 11, 2011 9:33 am

Re: Google News Extension

Postby Harm10 » Mon Jul 11, 2011 10:20 pm

Quality is in the detail of things............

Want to change or update your PivotX site? Mail or PM me!
I can also convert your site to a Wordpress site!
Harm10
Developer
 
Posts: 2011
Joined: Wed Jun 17, 2009 9:37 am
Location: Somewhere in The Netherlands (aka Holland)

Re: Google News Extension

Postby cablock » Mon Jul 25, 2011 11:07 pm

Thanks, I got this to work by rewriting the sitemap extension to output as follows:

<urlset>
<url>
<loc>http://www.siteurl.com/newsitem</loc>
<n:news>
<n:publication>
<n:name>News Source Name</n:name>
<n:language>en</n:language>
</n:publication>
<n:genres>UserGenerated</n:genres>
<n:title>Story Headline</n:title>
<n:publication_date>2011-07-21</n:publication_date>
<n:keywords>Some Keywords</n:keywords>
</n:news>
</url>

This is the format Google prefers for news.

However, I haven't managed to find how items are ordered (ascending/descending). If I can figure that out, I can add this extension for anyone else wanting to output entries to Google News. Any help in setting the order of items appreciated. It should start with most recent rather than first entry ever posted.

Thanks
cablock
 
Posts: 7
Joined: Mon Jul 11, 2011 9:33 am

Re: Google News Extension

Postby cablock » Mon Jul 25, 2011 11:11 pm

Also, you have to call Google sitemap schemes as in second line I added, to get the parameters needed to display as above.

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

Forgive my lack of code familiarity (I'm a designer) but I can follow the logic and have at least got it working :D

Setting a limit on how many entries show would also be useful. :shock:
cablock
 
Posts: 7
Joined: Mon Jul 11, 2011 9:33 am

Re: Google News Extension

Postby hansfn » Wed Aug 03, 2011 7:35 am

Since you have the extension almost ready, I'll give you the missing pieces in stead writing it myself. Please contribution the extension to the community when it's complete - see http://extensions.pivotx.net/page/extensions-guidelines (You can send it directly to me if you prefer - hansfn@pivotx.net)

Since the XML file should list news, I assume that you aren't including pages. So basically you are only listing the last N posted entries, right? If so, you can remove the "Iterate through the chapters and pages" part of the code if you haven't done so already. In addition, in the "Iterate through the entries in batches" part of the code, you don't need batches since you only want the last N entries. Just remove the outer $batches for loop and start directly at the read_entries call:

Code: Select all
        $entries = $PIVOTX['db']->read_entries(array('show' => N, 'order' => 'desc', 'full' => false, 'status'=>'publish'));
        foreach ($entries as $entry) {
            ...

The parameters for read_entries is documented.

Finally, you might want to make N, the number of news entries, a config setting, right? Look at the function xml_sitemapAdmin and modify.

Before submitting the code to us, make sure to rename everything from xml_sitemapwhatever to xml_news_sitemapwhatever (or someting similar).

Sorry about the late reply.
hansfn
Developer
 
Posts: 3282
Joined: Sun Nov 25, 2007 7:48 pm
Location: Molde, Norway

Re: Google News Extension

Postby cablock » Wed Aug 03, 2011 9:00 am

Thank you very much. Yes I am close now. If I get stuck I'll post back. I also need to test once more that Google will accept the map without errors. A preliminary check a few days ago seemed to indicate that the output was spot on. ;) - it was just the ordering and amount of links that needed resolving before I can say its done.
cablock
 
Posts: 7
Joined: Mon Jul 11, 2011 9:33 am

Re: Google News Extension

Postby cablock » Wed Nov 02, 2011 8:48 pm

Finally got around to setting this up. I only have two parameters I'm struggling with now - how to get the entry title and keywords. Whats the call for these?

http://www.cabnuneaton.org.uk/?xml_sitenewsmap

source is:

$output_item = <<<EOM
<url>
<loc>${host}%loc%</loc>
<n:news>
<n:publication>
<n:name>Brancab News</n:name>
<n:language>en</n:language>
</n:publication>
<n:genres>UserGenerated</n:genres>
<n:title>Need Title Here</n:title>
<n:publication_date>%lastmod%</n:publication_date>
<n:keywords>Need keywords/Tags here</n:keywords>
</n:news>
</url>
EOM;

Can I assume that to pull in this data, I actually need to work on these lines or those that follow?

$PIVOTX['db']->read_entry($entry['uid']);
$item = $output_item;
$item = str_replace('%loc%', $link, $item);

Presumably its something like $item = str_replace('%titel', ______, ______);
cablock
 
Posts: 7
Joined: Mon Jul 11, 2011 9:33 am

Re: Google News Extension

Postby hansfn » Thu Nov 03, 2011 10:11 am

You should quote code carefully so you don't introduce errors:

Code: Select all
            $entry = $PIVOTX['db']->read_entry($entry['uid']);
            $item = $output_item;
            $item = str_replace('%loc%', $link, $item);
            $item = str_replace('%lastmod%', formatDate($entry['edit_date'], '%year%-%month%-%day%'), $item);

The lines you need are something like:

Code: Select all
            $item = str_replace('%title%', $entry['title'], $item);
            $item = str_replace('%keywords%', $entry['keywords'], $item);
hansfn
Developer
 
Posts: 3282
Joined: Sun Nov 25, 2007 7:48 pm
Location: Molde, Norway

Re: Google News Extension

Postby cablock » Thu Nov 03, 2011 12:12 pm

Perfect! (see link above). Right, I'll tidy everything up and remove the code not needed and package it all up. I can't be the only one that could really use this extension. I was looking in the right place then. I'm not familiar with PHP but did figure out the logic :D
cablock
 
Posts: 7
Joined: Mon Jul 11, 2011 9:33 am

Re: Google News Extension

Postby hansfn » Thu Nov 03, 2011 1:14 pm

I tried your URL above. Looks OK, but the keywords should be comma-separated (according to the docs).

Replace

Code: Select all
            $item = str_replace('%keywords%', $entry['keywords'], $item);

with

Code: Select all
            $item = str_replace('%keywords%', preg_replace('/[ ]+/', ', ', $entry['keywords']), $item);


PS! Consider submitting the extension to our site - see http://extensions.pivotx.net/page/extensions-guidelines
hansfn
Developer
 
Posts: 3282
Joined: Sun Nov 25, 2007 7:48 pm
Location: Molde, Norway

Next

Return to 2.x Extensions

Who is online

Users browsing this forum: No registered users and 2 guests

cron