I want to use, same database, (content / users / comments / meta's / categories etc.) for another wordpress install in my sub directory.
I actually want to create mobile version of my site. But i dont want to use, any mobile detect script ory css3 media queries. Just want to create my new theme (for mobile version)
For example;
the main domain has also sub domain like ;
maindomain.com // root
mobile.maindomain.com // sub directory
How this could be possible ?
One of the nice things about WordPress is the great number of hooks in the code allowing you to extend or override core functionality.
One way to approach this problem would be to set an Apache environment variable in your vhost file for each site that could be used in the WordPress bootstrap process to over-ride the theme and base URL setup.
e.g. in Apache vhost add:
SetEnv WP_CONTEXT main
and
SetEnv WP_CONTEXT mobile
(or equivalent if you're using a different webserver).
In wp-config.php:
switch ($_SERVER['WP_CONTEXT']) {
case 'main':
define('WP_HOME','http://maindomain.com');
define('WP_SITEURL','http://maindomain.com');
break;
case 'mobile':
define('WP_HOME','http://mobile.maindomain.com');
define('WP_SITEURL','http://mobile.maindomain.com');
break;
}
This will set the base URLs based on the environment variable.
Then in plugin add the following filters:
add_filter('template', 'change_theme');
add_filter('option_template', 'change_theme');
add_filter('option_stylesheet', 'change_theme');
function change_theme()
{
switch ($_SERVER['WP_CONTEXT']) {
case 'main':
return 'main';
break;
case 'mobile':
return 'mobile';
break;
}
This needs to be in a plugin so that it's loaded before the normal theme loading process (functions.php is part of the theme and hence too late). These filters will intercept and over-ride the theme settings from the database.
You cant do that directly, as WP stores its url in database.
AFAIK there is a way to "link" tables in sql, so it might be the way - link everything beside wp_options for example, but still it is a tricky way.