Need code help

glhorsegal

New Member
Hello all,

I have taken the database from one site and created another site. With that said, I want to be able to change the city name via code and have it change through out the side. I have come up with this:

change every reference of the city name to something like <?=$cityName;?> and then in the main page, at the very top, add something like...

<?
$cityName = 'The City Name';
?>

With that said, my skill set in php is not strong enough to know if this will work and where to actually put it in. I am using WordPress and StudioPress theme

the website is: www.charlestonhomesforsale.com

Thanks for any help you can give me on this.
 

startup0101

New Member
Hello all,

I have taken the database from one site and created another site. With that said, I want to be able to change the city name via code and have it change through out the side. I have come up with this:

change every reference of the city name to something like <?=$cityName;?> and then in the main page, at the very top, add something like...

<?
$cityName = 'The City Name';
?>

With that said, my skill set in php is not strong enough to know if this will work and where to actually put it in. I am using WordPress and StudioPress theme

the website is: www.charlestonhomesforsale.com

Thanks for any help you can give me on this.

Hi there, what you are attempting to do is use a constant. A constant is a variable whose value is not meant to change throughout the execution of the code. If you simply want to define a city name and use it throughout the code, this is what I would recommend you do. You can do this in a couple ways, including the use of a define. Like this:
PHP:
define('CITYNAME', 'The City Name');

//Throughout the rest of the code, anywhere you put the text CITYNAME it will be replaced with the text The City Name.

This is the simplest way, you can also create a constant class and use the const keyword when defining the variables, let me know if you'd like to know this method and I will post it.

If you don't want to do either of those, what you said WILL in fact work, simply assigning it to a variable and using the variable throughout the rest of your code, however, note that if you do it this way and another page in your code happens to use the variable $cityName, its value could be changed accidentally.

Whichever method you chose, you should place it in a file include which is included before any files that use the constant/variable. I would suggest including it before any other file, place it all the way at the top.
 

nafirici

New Member
using php could work. Personally, I would change it in the database. I've never worked with WordPress, but I'd imagine the city is stored in limited places. Look at INFORMATION_SCHEMA.COLUMNS where like %city% and you will most likely find all the places to change it.
 
Hi there, what you are attempting to do is use a constant. A constant is a variable whose value is not meant to change throughout the execution of the code. If you simply want to define a city name and use it throughout the code, this is what I would recommend you do. You can do this in a couple ways, including the use of a define. Like this:
PHP:
define('CITYNAME', 'The City Name');

//Throughout the rest of the code, anywhere you put the text CITYNAME it will be replaced with the text The City Name.

This is the simplest way, you can also create a constant class and use the const keyword when defining the variables, let me know if you'd like to know this method and I will post it.

If you don't want to do either of those, what you said WILL in fact work, simply assigning it to a variable and using the variable throughout the rest of your code, however, note that if you do it this way and another page in your code happens to use the variable $cityName, its value could be changed accidentally.

Whichever method you chose, you should place it in a file include which is included before any files that use the constant/variable. I would suggest including it before any other file, place it all the way at the top.

can i request that you post it here? i mean, i also would like to know..
 
Top