How 2 automate Wordpress to build Static Pages for different States?

dmnEPC

New member
Dec 23, 2010
5,994
95
0
I just got done wasting about 2 hours doing a very repetitive task on one of my WordPress sites and would really like to avoid repeating this painstaking process again.

What I am am trying to do is Automate the process of setting up Static Pages with like 95% same content. Basically what I am doing is setting up a Static page for all 50 states and maybe top 10 cities in each state. The content and images would be the same but would have unique links and the States (and maybe cities) names brought into it. Which would also have a table on each page with all 50 states (more than likely I would just put it in the footer) I'm not looking at a Geo Redirect just building the pages for SEO.

So I guess there is a couple problems I am trying to solve

1 Automatically build the Pages so each page name would be Domain.com/state or Domain.com/city

2. Pull the content and then update the the states info for that unique page and also update the links.

Is this something that can be accomplished w/ some sort of Plugin? Ubot? Or im guessing this would probably be written in PHP? I really couldn't find much on this so if anyone has any thoughts or suggestions it would be appreciated. Thanks
 


It's actually pretty easy to do if you are familiar with WP's structure, and can code a little.

Sounds like you aren't a programmer though.

I've written a number of geographical posters for WP - so drop me a pm if you are looking for something coded for you.
 
Just code it in php using mysql database and .htaccess rewrites? Pretty simple

The php would do the links automatically and the rewrites would make the static dynamic pages, would hardly take much php at all and you could just do a find replace in something like dreamweaver to create sqls to insert the states and cities into a database so you don't have any manual work that wastes time!
 
I am not a coder but can definitely find my way around the WP structure and my PHP skills are certainly not great pretty much can figure what needs to be changed in the existing code to make it work the way I want it to, you know easy stuff. I'm not really afraid of it just kinda looking to be pointed in the right direction (which you already have) it helps to know the name of what I am trying to do :) Ill
 
Hey thanks guys. I think I should be able to figure it out. Now that I know what I am looking for. Thanks
 
Basic run down of what you need to do..... and that will let you go back and add content in easier.

1.) Store wordpress login details in database.

2.) Use the WP xml-rpc api or read database to determine the category id number you are currently on.

3.) Use the xml-rpc library to create the 50 state categories. Each one you create is 1 id number higher so it's easy to keep track of.

Store those category id's in the database so you can reference them again

4.) Post for each city in each state to the proper category in wp. Plenty of ways to make each post unique as you go along.

If you get stuck somewhere let me know - I've built a bunch of them for the seo firms I do work for over the last couple years.
 
Basic run down of what you need to do..... and that will let you go back and add content in easier.

1.) Store wordpress login details in database.

2.) Use the WP xml-rpc api or read database to determine the category id number you are currently on.

3.) Use the xml-rpc library to create the 50 state categories. Each one you create is 1 id number higher so it's easy to keep track of.

Store those category id's in the database so you can reference them again

4.) Post for each city in each state to the proper category in wp. Plenty of ways to make each post unique as you go along.

If you get stuck somewhere let me know - I've built a bunch of them for the seo firms I do work for over the last couple years.


Ok so I think i got the gist of this. So if I understood you correct assuming my highest category id in the DB is for example 100 then I would just set the library from 101 and then work my way up? And I assume that this wouldn't really affect any future post's or pages done after these pages are setup?

After checking it out, it doesn't look like it should be that big of a deal to do this. Thanks again for your help.
 
Hey thanks alot stmadeveloper great resource. Ill work through it. I should be able to figure it out. Thanks again for your help
 
This will create it for you, is pretty easy and straight forward, if you can hack basic PHP. I tested it on a latest version of WP, so it works.

Code:
<?PHP



$states = array(
				"AL" => "Alaska",
                "CA" => "California",
                "CO" => "Colorado",
                "TX" => "Texas"
                );
                
	$link = mysql_connect('localhost', 'DATABASEUSER', 'DATABASEPASSWORD');
	if (!$link) 
		{
   			 die('Could not connect: ' . mysql_error());
		}
	else
		{
			echo 'Connected successfully';
		}

	$db_selected = mysql_select_db('DABASENAME', $link);
	if (!$db_selected) 
		{
    		die ('Can\'t use mysql db : ' . mysql_error());
		}
		
	
	$post_author = "1";  	//ID from wordpress of the author
	
	
	
	
	foreach($states as $stateshort => $statelong)
		{
			$post_content = "All of the content goes here, and use the variable $statelong where you want the name of the state to appear ";
	
			$post_title = "TItle about $statelong ";
			
			$post_name = "title-about-".strtolower($statelong);
			
			$sql = "
							INSERT INTO 
								wp_posts
									(
									 	post_author,
										post_date,
										post_date_gmt,
										post_content,
										post_title,
										post_status,
										comment_status,
										ping_status,
										post_name,
										post_modified,
										post_modified_gmt,
										post_type
									)
								VALUES
									(
									 	'$post_author',
										NOW(),
										NOW(),
									 	'$post_content',
										'$post_title',
										'publish',
										'open',
										'open',
										'$post_name',
										NOW(),
										NOW(),
										'page'
									)
				";
			$result = mysql_query($sql);
			if (!$result) 
				{
					die('Invalid query: ' . mysql_error());
				}
			else
				{
					echo "<BR>created page for ".$statelong;
				}
										
			
		}
 
So I have been playin with this for a while and not really sure what i screwed up. I went and updated all of the info in the code (what I added is below) that I could figure needed to be, and when I uploaded the file it does successfully connect. But I am getting the following error

connected successfullyInvalid query: Query was empty

I'm sure i missed something just not sure what. So its connecting, I am not getting any errors in Zend, Is there something that needs to be changed in the INSERT INTO section? Or something simpler than that? Again my thanks to everyone who has helped me out with this its very much appreciated.

[high=php]

<?PHP



$states = array(
"AL" => "Alaska",
"CA" => "California",
"CO" => "Colorado",
"TX" => "Texas",
"AL" => "ALABAMA",
"AK" => "ALASKA",
"AZ" => "ARIZONA",
"AR" => "ARKANSAS",
"CA" => "CALIFORNIA",
"CO" => "COLORADO",
"CT" => "CONNECTICUT",
"DE" => "DELAWARE",
"DC" => "DISTRICT OF COLUMBIA",
"FL" => "FLORIDA",
"GA" => "GEORGIA",
"HI" => "HAWAII",
"ID" => "IDAHO",
"IL" => "ILLINOIS",
"IN" => "INDIANA",
"IA" => "IOWA",
"KS" => "KANSAS",
"KY" => "KENTUCKY",
"LA" => "LOUISIANA",
"ME" => "MAINE",
"MD" => "MARYLAND",
"MA" => "MASSACHUSETTS",
"MI" => "MICHIGAN",
"MN" => "MINNESOTA",
"MS" => "MISSISSIPPI",
"MO" => "MISSOURI",
"MT" => "MONTANA",
"NE" => "NEBRASKA",
"NV" => "NEVADA",
"NH" => "NEW HAMPSHIRE",
"NJ" => "NEW JERSEY",
"NM" => "NEW MEXICO",
"NY" => "NEW YORK",
"NC" => "NORTH CAROLINA",
"ND" => "NORTH DAKOTA",
"OH" => "OHIO",
"OK" => "OKLAHOMA",
"OR" => "OREGON",
"PA" => "PENNSYLVANIA",
"RI" => "RHODE ISLAND",
"SC" => "SOUTH CAROLINA",
"SD" => "SOUTH DAKOTA",
"TN" => "TENNESSEE",
"TX" => "TEXAS",
"UT" => "UTAH",
"VT" => "VERMONT",
"VA" => "VIRGINIA",
"WA" => "WASHINGTON",
"WV" => "WEST VIRGINIA",
"WI" => "WISCONSIN",
"WY" => "WYOMING ",


);

$link = mysql_connect('localhost', 'MY USER NAME', 'MY PASSWORD');
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
else
{
echo 'Connected successfully';
}

$db_selected = mysql_select_db('MyUniqueDataBASE_wrdp14', $link);
if (!$db_selected)
{
die ('Can\'t use mysql db : ' . mysql_error());
}


$post_author = "1"; //ID from wordpress of the author




foreach($states as $stateshort => $statelong)
{
$post_content = "Blah bla Blah Blah bla BlahBlah bla BlahBlah bla BlahBlah bla Blah
Blah bla BlahBlah bla BlahBlah bla BlahBlah bla BlahBlah bla Blah
Blah bla BlahBlah bla BlahBlah bla BlahBlah bla BlahBlah bla BlahBlah bla Blah
Blah bla BlahBlah bla Blah $statelong Blah bla BlahBlah bla BlahBlah bla Blah $statelong.
yBlah bla BlahBlah bla BlahBlah bla BlahBlah bla BlahBlah bla BlahBlah bla BlahBlah bla Blahl.;

$post_title = Blah Blah $statelong;

$post_name = blah-bla-bllla-.strtolower($statelong);

$sql = MyUniqueDataBASE_wrdp14
INSERT INTO,
wp_posts
(
post_author,
post_date,
post_date_gmt,
post_content,
post_title,
post_status,
comment_status,
ping_status,
post_name,
post_modified,
post_modified_gmt,
post_type
)
VALUES
(
'$post_author',
NOW(),
NOW(),
'$post_content',
'$post_title',
'publish',
'open',
'open',
'$post_name',
NOW(),
NOW(),
'page'
)
";
$result = mysql_query($sql);
if (!$result)
{
die('Invalid query: ' . mysql_error());
}
else
{
echo "<BR>created page for ".$statelong;
}


}

[/high]
 
You really have to watch out for the single quotes and the double quotes, yours were totally messed up. I just ran this:

PHP:
<?PHP

$states = array("AL" =>"Alaska",
"CA" => "California",
"CO" => "Colorado",
"TX" => "Texas",
"AL" => "ALABAMA", 
"AK" => "ALASKA", 
"AZ" => "ARIZONA", 
"AR" => "ARKANSAS", 
"CA" => "CALIFORNIA", 
"CO" => "COLORADO", 
"CT" => "CONNECTICUT", 
"DE" => "DELAWARE", 
"DC" => "DISTRICT OF COLUMBIA", 
"FL" => "FLORIDA", 
"GA" => "GEORGIA", 
"HI" => "HAWAII", 
"ID" => "IDAHO", 
"IL" => "ILLINOIS", 
"IN" => "INDIANA", 
"IA" => "IOWA", 
"KS" => "KANSAS", 
"KY" => "KENTUCKY", 
"LA" => "LOUISIANA", 
"ME" => "MAINE", 
"MD" => "MARYLAND", 
"MA" => "MASSACHUSETTS", 
"MI" => "MICHIGAN", 
"MN" => "MINNESOTA", 
"MS" => "MISSISSIPPI", 
"MO" => "MISSOURI", 
"MT" => "MONTANA", 
"NE" => "NEBRASKA", 
"NV" => "NEVADA", 
"NH" => "NEW HAMPSHIRE", 
"NJ" => "NEW JERSEY", 
"NM" => "NEW MEXICO", 
"NY" => "NEW YORK", 
"NC" => "NORTH CAROLINA", 
"ND" => "NORTH DAKOTA", 
"OH" => "OHIO", 
"OK" => "OKLAHOMA", 
"OR" => "OREGON", 
"PA" => "PENNSYLVANIA", 
"RI" => "RHODE ISLAND", 
"SC" => "SOUTH CAROLINA", 
"SD" => "SOUTH DAKOTA", 
"TN" => "TENNESSEE", 
"TX" => "TEXAS",
"UT" => "UTAH", 
"VT" => "VERMONT", 
"VA" => "VIRGINIA", 
"WA" => "WASHINGTON", 
"WV" => "WEST VIRGINIA", 
"WI" => "WISCONSIN", 
"WY" => "WYOMING ", 


);

$link = mysql_connect('localhost', 'wpusername', 'wppassword');
if (!$link) 
	{
		die('Could not connect: ' . mysql_error());
	}
else
	{
		echo 'Connected successfully';
	}

	$db_selected = mysql_select_db('wpdatabasename', $link);
	if (!$db_selected) 
		{
			die ('Can\'t use mysql db : ' . mysql_error());
		}


$post_author = "1"; //ID from wordpress of the author




foreach($states as $stateshort => $statelong)
{
	$post_content = "$statelong Blah bla Blah Blah bla BlahBlah bla BlahBlah bla BlahBlah bla Blah
	Blah bla BlahBlah bla BlahBlah bla BlahBlah bla BlahBlah bla Blah 
	Blah bla BlahBlah bla BlahBlah bla BlahBlah bla BlahBlah bla BlahBlah bla Blah
	Blah bla BlahBlah bla Blah $statelong Blah bla BlahBlah bla BlahBlah bla Blah $statelong. 
	yBlah bla BlahBlah bla BlahBlah bla BlahBlah bla BlahBlah bla BlahBlah bla BlahBlah bla Blahl.";
	
	$post_title = "Blah Blah ".$statelong;
	
	$post_name = "blah-bla-bllla-".strtolower($statelong);
	
	$sql = "
	INSERT INTO
		wp_posts
			(
				post_author,
				post_date,
				post_date_gmt,
				post_content,
				post_title,
				post_status,
				comment_status,
				ping_status,
				post_name,
				post_modified,
				post_modified_gmt,
				post_type
		)
	VALUES
		(
			'$post_author',
			NOW(),
			NOW(),
			'$post_content',
			'$post_title',
			'publish',
			'open',
			'open',
			'$post_name',
			NOW(),
			NOW(),
			'page'
		)
	";
	echo "<PRE>";
	print_r($sql);
	echo "</PRE>";
	
	$result = mysql_query($sql);
	if (!$result) 
		{
			die('Invalid query: ' . mysql_error());
		}
	else
		{
			$postid = mysql_insert_id();
			$sql = "INSERT INTO
						wp_postmeta
							(
							 	post_id,
								meta_key,
								meta_value
							)
						VALUES
							(
							 	'$postid',
								'_wp_page_template',
								'default'
							 
							 )
						";
			$result = mysql_query($sql);
			echo "<BR>
			created page for ".$statelong;
		}
	
	

}?>
 
+Rep

That worked like a dream. I am very appreciative of your help with this. I know that this will be helpful to other WF members and think that you should post the code in the Sticky thread WF PHP Functions War Chest. Its simple its sleek and it works great. This is a real time saver. Thanks again