HOWTO: run 1 blog from 2 URLs / run 1 database with 2 sets of files
-
You know the problem. You want to work on your wordpress theme offline, on your own personal copy of the blog; but you want to keep all the files in sync with your web site, and use the same database.
But wordpress insists on linking all the links back to your real, online blog. How to tell it to use the URL of your local blog locally, and your remote blog remotely?
Here’s a hack to make wordpress pick up the URL for itself, every time!
open up
wp-includes/functions.php
and find the part which says:/* Options functions */
function get_settings($setting) {
global $wpdb;
$value = wp_cache_get($setting, 'options');
if ( false === $value ) {
if ( defined('WP_INSTALLING') )
$wpdb->hide_errors();
and change it to say this:
/* Options functions */function get_settings($setting) {
global $wpdb;
$value = wp_cache_get($setting, 'options');
/* Ben XO's siteurl hack */
if( 'siteurl' == $setting or 'home' == $setting ) {
$_REAL_SCRIPT_DIR = realpath(dirname($_SERVER['SCRIPT_FILENAME']));
$_REAL_BASE_DIR = realpath(dirname(__FILE__).'/..');
$_MY_PATH_PART = substr( $_REAL_SCRIPT_DIR, strlen($_REAL_BASE_DIR));
$INSTALLATION_PATH = $_MY_PATH_PART
? substr( dirname($_SERVER['SCRIPT_NAME']), 0, -strlen($_MY_PATH_PART) )
: dirname($_SERVER['SCRIPT_NAME'])
;
$value = 'http' . ($_SERVER['HTTPS'] ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $INSTALLATION_PATH;
}
/* end Ben XO's siteurl hack */
if ( false === $value ) {
if ( defined('WP_INSTALLING') )
$wpdb->hide_errors();
it uses a trick i posted on the PHP comments page, here:
http://uk.php.net/manual/en/reserved.variables.php#reserved.variables.server
happy developing!
-
ah har. my apologies. it’s not immediately obvious. i was wondering my i had to log in multiple times… there does seem to be a bit of ambiguity between a blog from wordpress.com and a blog from wordpress.org :p
- The topic ‘HOWTO: run 1 blog from 2 URLs / run 1 database with 2 sets of files’ is closed to new replies.