Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-10-03 15:18:31

beechy
Member
Registered: 2006-03-02
Posts: 92

Inclusion in Google News

I am trying to get our blog included in Google news at the moment.

Our urls for the blog are setup as – www.websiteurl/blog/article-title

However the Google news guidelines for articles specify that the url must contain three unique numbers:

( http://www.google.com/support/news_pub/bin/answer.py?hl=en-GB&answer=68323 )

i.e www.websiteurl/blog/article-title-123

I know I could do this manually by editing the ‘URL-only title’ for each new article but I was hoping that there would be an easy way to append the textpattern article id to the end of the url automatically for all new blog articles going forward. I don’t want to change any of the old blog article urls so changing the permanent link mode isn’t an option.

Does anyone have any ideas how I could best do this?

Offline

#2 2011-10-03 17:13:29

towndock
Member
From: Oriental, NC USA
Registered: 2007-04-06
Posts: 335
Website

Re: Inclusion in Google News

You could change your Permanent link mode (under Admin / Preferences) to section/id/title. That way each article url would include the article ID number. Provided you have more than 99 articles, that would be at least a three digit number.

However, there is perhaps a better option. Note that Google says “Please note that this rule is waived with News sitemaps.”

Add a News site map to Google specs:

http://www.google.com/support/news_pub/bin/answer.py?answer=74288&hl=en-GB

Offline

#3 2011-10-03 21:17:58

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,001
Website GitHub

Re: Inclusion in Google News

To add to towndock’s suggestion of using a section/id/title url scheme, it seems that txp will happily accept the id as 3-digit number.

You should be able to use the following to construct the article id number as a 3-digit number (untested):

<txp:php>global $thisarticle; echo sprintf("%03d", $thisarticle['thisid']);</txp:php>

You’d have to construct your own permlinks instead of using the txp:permlink function with the above used to output the article id.

<txp:site_url /><txp:section />/<txp:php>global $thisarticle; echo sprintf("%03d", $thisarticle['thisid']);</txp:php>/<txp:article_url_title />

Alternatively if google news allows the 3-figure number to be an url query string, you could just tag it onto the end of the normal url, e.g. (again, untested):

<txp:permlink />?news_id=<txp:php>global $thisarticle; echo sprintf("%03d", $thisarticle['thisid']);</txp:php>

TXP Builders – finely-crafted code, design and txp

Offline

#4 2011-10-03 21:59:27

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Inclusion in Google News

Another possible approach, using internal rewrites:

You could do it by crafting the permlinks (similarly to what jakob suggested):

<txp:site_url /><txp:section />/<txp:article_url_title />-00<txp:article_id />

Or even just:

<txp:permlink />-00<txp:article_id />

I added two leading zeros to be sure it’s, at least, a three digit number. But you could try to do it just for the first 99 ids using PHP str_pad function. Or even using an smd_if plugin (by testing the id value < 100 or even the id length < 3).

Then, in your .htaccess:

RewriteEngine On
# RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]

# ** Here is the trick **
# This would rewrite  any URL ending in "-123" to the same URL without the number.
RewriteRule ^(.*)-([0-9]+)$ $1

RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*) index.php

RewriteCond %{HTTP:Authorization}  !^$
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]

Haven’t tested the rewrite rule, so I can’t guarantee it will work out of the box. We may need to revise it, so report back if you have success (or not) :)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB