使用具有不同的wordpress主题的两个域相同的数据库 [英] using two domain same database with different wordpress theme

查看:165
本文介绍了使用具有不同的wordpress主题的两个域相同的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用相同的数据库(内容/用户/注释/元数据/类别等)在我的子目录中安装另一个wordpress.

I want to use, same database, (content / users / comments / meta's / categories etc.) for another wordpress install in my sub directory.

我实际上想创建网站的移动版本.但我不想使用任何移动检测脚本或CSS3媒体查询.只想创建我的新主题(用于移动版本)

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)

例如;

主域也有子域,如;

maindomain.com // root
mobile.maindomain.com // sub directory

这怎么可能?

推荐答案

关于WordPress的一件好事是代码中的大量钩子,使您可以扩展或覆盖核心功能.

One of the nice things about WordPress is the great number of hooks in the code allowing you to extend or override core functionality.

解决此问题的一种方法是在vhost文件中为每个站点设置一个Apache环境变量,该站点可以在WordPress引导过程中使用以覆盖主题和基本URL设置.

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.

例如在Apache vhost中添加:

e.g. in Apache vhost add:

SetEnv WP_CONTEXT main

SetEnv WP_CONTEXT mobile

(如果您使用其他网络服务器,则为等效).

(or equivalent if you're using a different webserver).

在wp-config.php中:

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;
}

这将根据环境变量设置基本URL.

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;
}

这需要在插件中,以便在正常主题加载过程之前加载(functions.php是主题的一部分,因此为时已晚).这些过滤器将拦截并覆盖数据库中的主题设置.

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.

这篇关于使用具有不同的wordpress主题的两个域相同的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆