Go to GoReading for breaking news, videos, and the latest top stories in world news, business, politics, health and pop culture.

How To Make Dynamically Generated Title Tags That Are Indexed By Search Engines

103 1
First off you need a bit of basic scripting knowledge of both Python and PHP.
If you don't have knowledge in these areas look towards the end of the article for a link to a great Python tutorial.
It's lengthy but worth it - its great for automatically generating text.
Once you have done that tut, you'll be able to get by with minimal PHP knowledge using the greatest tutorial of our time – "Google it" (not strictly a tutorial but you get the idea).
Secondly, somewhere in the source code of the page you are wanting to have a dynamically generated title tag for, you need to have a line that contains the title you want – e.
g.
<td valign="top">African Lions</td>.<br/> You need a line with just one tag so if its not, make it so.
Thirdly, you need, in the dynamically generated page an URL that contains a unique identifier value – eg.
[http://www.
somesite.
com/index.
php?id=9898] (the id=9898 being the identifier).
Fourthly, this article is a follow on from my previous article "URL Rewriting - Get Rid of Those Ugly Dynamic URLs" so please read that first.
Then you're ready to go, just edit that line mentioned above so it contains the words "forPython" in the code – eg.
<td valign="top"> African Lions </td>.<br/> Then you want to write a Python script that extracts the line mentioned above and then extracts the words African Lions (for example) from that.
You'll need to have at least version 2.
5 to do this.
I used code similar to the following: from cStringIO import StringIOfrom xml.<br/>etree import ElementTreeimport urllib2def gettext(url):for line in urllib2.<br/>urlopen(url):#Created special id in the line where I want the information (lion cubs & lioness)if 'id="forPython"' in line:parsed_line = ElementTree.<br/>parse(StringIO(line))root = parsed_line.<br/>getroot()x = root.<br/>textx = str(x)return x#You'd want to change the line below so that it ranges in the range of the unique identifier that you've got hold of (e.<br/>g.<br/> id=9898)for page in range(0,10000):page = str(page)#The line below should be changed to your new mod rewritten URL x = gettext("http://www.<br/>africapic.<br/>com/index/closeup/102-"+page+"-0.<br/>html")print page, xmyfile=open(page+'.<br/>txt','w')myfile.<br/>write(x+"n")myfile.<br/>close() The import values that you would want to change would be in the lines "for page in range(0, 10000)" and "x=gettext("http://...
").
The first line that would be changed so that between the two numbers all the possible values for the unique identifier are accounted for.
For example if my pages ranged from id=1000 to id=9999 I would put "for page in range(1000,9999)".
The second line would be changed so that it "fetches" your newly mod rewritten pages (e.
g.
[http://www.
somesite.
com/this/that/50-]"+page+"-28.
html) or even (e.
g.
[http://www.
somesite.
com/this/that/]"+page+".
html) in some cases.
This script would write 10000 text files (if the values for range were correct) each containing the words in the <td> tag.<br/> So what do you do with these files? Upload them to your server in a folder and then on to the PHP.<br/>You'll need to edit your index.<br/>php file here (or at least a PHP file called by index.<br/>php).<br/> Firstly put the following code in the title tag:<xmp><title><?php print $title ?></title> Then you'll need to add code similar to the following to the beginning of the file (above the title tag): // if URI in format index.<br/>php?...<br/>id=1000 assign value to id$id =$_GET['id'];// sitemap = string file name with id;$sitemap = ".<br/>/sitemap/100-".<br/>$id.<br/>".<br/>txt";// This will open the file, in folder 'sitemap' that has the Media Name on the first line, and assign that file to an array;$file_lines_array = file($sitemap);$title = $file_lines_array[0];
Source...

Leave A Reply

Your email address will not be published.