Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#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
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
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
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) :)
Offline
Pages: 1