問題描述
是否可以集中管理多站點安裝的內容?如果我有 20 個網站的網絡,是否可以在一個網站上更改內容,並在網絡上進行更新,或者我必須一次更改每個網站?更具體的情況是,如果我有一個必須出現在每個站點上的 「條款和條件」 頁面,這需要定期更改,我可以進行更改並將其複製。
任何有效管理此過程的建議/方向/資源將不勝感激。
最佳解決方法
我已成功使用 ThreeWP Broadcast 插件在 WPMU 安裝上執行此操作。
基本概念是您有一個’broadcasting’ 站點,您可以從其中將內容廣播到其他站點。內容可以是帖子,頁面,自定義帖子類型,自定義分類法,後期元數據或附件。
如果內容在’broadcasting’ 網站上更新,則更新將反映在其他網站上。更多信息可以在上面鏈接的 ThreeWP Broadcast WP Plugin Directory 條目中找到。
次佳解決方法
我有一個類似的問題,我需要內容可用”network-wide” 並從一個位置 (主要網站) 管理,所以我創建了一個自定義的帖子類型在主要的網站稱為”shared content” 和一個漂亮的小短碼,從主要網站的內容。
這裏是”a version”,但它並沒有測試,因為我沒有訪問我當時使用的工作解決方案,但它應該工作正常:
<?php
/*
Plugin Name: WPMU Shared Content
Plugin URI: http://en.bainternet.info
Description: This plugin lets you create and manage content on the main MU installation and shared it accros you network
Version: 0.1
Author: Bainternet
License:
Copyright 2012 Bainternet (admin@bainternet.info)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Disallow direct access to the plugin file */
if (basename($_SERVER['PHP_SELF']) == basename (__FILE__)) {
die('Sorry, but you cannot access this page directly.');
}
if (!class_exists('wpmu_shared_content')){
/**
* wpmu_shared_content
*/
class wpmu_shared_content
{
static $main_site_id;
static $current;
//class constructor
public function __construct($main_id = 1);
{
global $blog_id;
$this->main_site_id = $main_id
$this->current = $blog_id;
//only register the post type to the main side
if (is_main_site($this->main_site_id) && is_super_admin())
add_action( 'init', array($this,'register_shared_content' ));
add_shortcode('sh',array($this,'load_shared_content'));
add_shortcode('SH',array($this,'load_shared_content'));
}
//register custom post type shared content
public function register_shared_content() {
$labels = array(
'name' => _x( 'Shared Content', 'shared_content' ),
'singular_name' => _x( 'shared_content', 'shared_content' ),
'add_new' => _x( 'Add New', 'shared_content' ),
'add_new_item' => _x( 'Add New shared_content', 'shared_content' ),
'edit_item' => _x( 'Edit shared_content', 'shared_content' ),
'new_item' => _x( 'New shared_content', 'shared_content' ),
'view_item' => _x( 'View shared_content', 'shared_content' ),
'search_items' => _x( 'Search Shared Content', 'shared_content' ),
'not_found' => _x( 'No shared content found', 'shared_content' ),
'not_found_in_trash' => _x( 'No shared content found in Trash', 'shared_content' ),
'parent_item_colon' => _x( 'Parent shared_content:', 'shared_content' ),
'menu_name' => _x( 'Shared Content', 'shared_content' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'description' => 'Content to be shared with all sites but managed form main installation only.',
'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_icon' => 'http://i.imgur.com/LI2B6.png',
'show_in_nav_menus' => true,
'publicly_queryable' => false,
'exclude_from_search' => false,
'has_archive' => false,
'query_var' => false,
'can_export' => true,
'rewrite' => false,
'capability_type' => 'post'
);
register_post_type( 'shared_content', $args );
}
//shortcode handler
public function load_shared_content($atts,$content=null){
extract(shortcode_atts(
array('id' => 0),
$atts));
$retVal = "";
if ($id <= 0)
return $retval;
$shared_content = get_blog_post($this->main_site_id,$id);
$retVal = apply_filters('the_content',$shared_contents['post_content']);
return $retVal;
}
}//end class
}//end if
if (is_multisite())
new wpmu_shared_content(apply_filters('wpmu_shared_content_main_site_id', 1));
/**
* Usage: [sh id="3"] or [SH id= 3]
*/
第三種解決方法
bainternet 和 davemac 的答案是偉大的,如果不是有點沉重的手。我有一個類似的情況,我有 5 個博客運行,一個”master” 博客,保持所有的全球使用條款和隱私政策的事情。我是怎麼做到的呢
-
在您的主要博客中,創建您的網頁,然後設置一個名為”global” 的導航菜單,其中包含您想要全局共享的所有頁面。
-
將以下代碼添加到您的主題,無論您想要顯示全局導航:
if (is_multisite()) switch_to_blog(1); //if the global blog is #1 wp_nav_menu( array( 'theme_location' => 'global' ) ); restore_current_blog(); -
您可以將上述代碼添加到窗口小工具,如果您在窗口小工具中需要它。
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。