自定义网站

时间:2015-04-29 10:48:21

标签: wordpress multisite

我刚刚安装了带有映射域的wordpress多站点安装(版本4.2.1)。

对于每个网站,浏览器中显示的上传图片的网址为http://URL/wp-content/uploads/sites/SITENUMBER/DATE/...,文件夹为/path/to/wordpress/wp-content/uploads/sites/SITENUMBER/DATE/...。 但我想使用本地路径/path/to/wordpress/wp-content/uploads/sites/SITENUMBER/...,并希望在浏览器http://URL/wp-content/uploads/DATE/...中看到(就像在一个wordpress网站中一样)。

我已经阅读了很多相关内容,我想我知道选项“UPLOAD URL PATH”通常应该重写这个,不是吗?但对我来说它不起作用。我怎么能自定义wordpress以适应它呢?

更新:我发现在functions.php中定义多站点将重写URL:

// If multisite (and if not the main site in a post-MU network)
if ( is_multisite() && ! ( is_main_network() && is_main_site() && defined( 'MULTISITE' ) ) ) {

if ( ! get_site_option( 'ms_files_rewriting' ) ) {
/*
* If ms-files rewriting is disabled (networks created post-3.5), it is fairly
* straightforward: Append sites/%d if we're not on the main site (for post-MU
* networks). (The extra directory prevents a four-digit ID from conflicting with
* a year-based directory for the main site. But if a MU-era network has disabled
* ms-files rewriting manually, they don't need the extra directory, as they never
* had wp-content/uploads for the main site.)
*/

    if ( defined( 'MULTISITE' ) )
        $ms_dir = '/sites/' . get_current_blog_id();
    else
        $ms_dir = '/' . get_current_blog_id();

    $dir .= $ms_dir;
    $url .= $ms_dir;
    ...
}}

但我不知道如何改变它以获得所需的行为。

1 个答案:

答案 0 :(得分:1)

是的,您可以使用以下功能更改WordPress中的上传目录。

add_filter( 'upload_dir', 'upload_dir_filter' );

function upload_dir_filter( $upload ) {
    $dir = $_SERVER['DOCUMENT_ROOT'];
    $upload_dir = $dir['basedir'] . '/uploads/date';
    $upload_url = $dir['baseurl'] . '/uploads/date';

    wp_mkdir_p( $upload_dir );  //WordPress will check if the dir exists and can write to it.
    $upload['path'] = $upload_dir;
    $upload['url']  = $upload_url;

        return $upload;
    }