Forum Moderators: rogerd & travelin cat

Message Too Old, No Replies

Dynamic Landing Page Template (Just Change City Name) Based On URL?

         

Planet13

9:06 pm on May 29, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi all,

i would like to make about 20 pages (not posts) in wordpress where 99% of the information is the same.

The only difference would be in the City Names, which would appear in the page title and in the body of the text.

This would be for an adwords campaign, and I would no index these from search engines.

Is there a way to do this where they could be created dynamically based on parameters in the URL?

.I would rather NOT have to create 20 new pages by hand and then have to update each one by hand whenever I needed to make a small text change.

Thanks in advance.

not2easy

10:49 pm on May 29, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



If it would be enough help for you, you can always create your own page template and populate the variables as you publish the pages. (Substitute 'post/s' if that's your preference.) the filename may vary according to the theme's creator, usually for pages it is called 'page.php' or for posts: 'single.php'. You build one page/post, then paste the source code into its new template and name it mypage.php or mysingle.php and save it to your theme. When you are ready to publish the post or page, just use the custom template. Not all themes have the functionality built in, but it is common to most themes.

You can get details here: [codex.wordpress.org...]
(In case the link anchor doesn't take you to the correct section of that page, it is listed in the Content Menu as "2.4.3 Custom Page Templates").

Planet13

11:54 pm on May 29, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks for the reply, not2easy.

I think what I want is something a little bit different.

Or maybe I am misunderstanding what you are sayng.

I want to create 20 landing pages that are nearly exactly the same.

Just in two places on each page, the name of the city will change.

My preference (if at all possible) would be to have ONE page, and use tokens for the city name.

Then if the URL had a parameter in it, that one page would display using the city name that is designated by the parameter.

So if my adwords URl was:

example.com/chicago

The landing page would use the word "Chicago" wherever I placed a token.

If the URL was

example.com/newyork

The landing page would use the words "New York" wherever I placed a token.

So if I needed to update the rest of the text on the page (aside from the dynamic city name), then I would only have to update ONE page, not 20 pages.

Is that doable with what you suggested?

Thanks in advance.

not2easy

12:52 am on May 30, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Yes, it is doable. Template Tags offer the dynamic type of text insertion you asked about, this page: [codex.wordpress.org...] is linked to from the page linked to above.

lucy24

1:02 am on May 30, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I would rather NOT have to create 20 new pages by hand

Seems as if you're skipping over a heck of a big middle ground here. Even if it weren't a WP site you would never have to hand-roll the page; it would be an html/php page that's 90% straight HTML and only briefly detours into PHP whenever it needs to use the value of a variable. (With only 20 or so, and only used by one page, I'd be tempted to save the server some work by simply listing those variables right in the page itself. I mean, er, in the php, not the visible html!)

Planet13

8:06 pm on May 30, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



@ Lucy24:

You are one of the reasons I still come to webmasterowrld for advice.

Thank you for bailing me out of my prolonged brain cramp.

So what I interpret your suggestion to be is:

1) Create a single page in wordpress

2) Use view source, copy and paste into a file with .php as the extension

3) Use a variable (such a $city_name or whatever)

4) Pass the variable in the URL

Man, it has been so long since I have done just basic php programming. do I need to declare variables in PHP 5? do I have to sanitize it if the variable passed in the URL is NOT going to be written in the database? (It will just be displayed in the html during run time)

Thanks again.

lucy24

8:56 pm on May 30, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



do I need to declare variables in PHP 5? do I have to sanitize it if the variable passed in the URL is NOT going to be written in the database?

I dunno, ask in the php subforum. It would be grossly irresponsible of me to answer any concrete questions, since I only speak about three words of php. Paradoxically, that's why I stepped in to the present thread: I don't normally approve of the locution "If I can do it, anyone can" (unless the speaker is already known to be the single least competent person on the entire planet) but in this case: If I can do it in php, anyone can.

I think if php ever turned around and required you to declare variables (meaning that non-declared variables are what? global, or fatal errors?), the world would come to an end ;)

Planet13

9:56 pm on May 30, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think if php ever turned around and required you to declare variables (meaning that non-declared variables are what? global, or fatal errors?), the world would come to an end ;)


Well, I have been saving up canned meat for the Apocalypse.

After all, it's Apocalicious!

toidi

11:03 am on May 31, 2015 (gmt 0)

10+ Year Member Top Contributors Of The Month



Or make one page, copy 20 times, and manually insert the different cities. In the time you spend researching this you can have it done.