本篇文章更新時間:2019/02/16
如有資訊過時或語誤之處,歡迎使用 Contact 功能通知。
一介資男的 LINE 社群開站囉!歡迎入群聊聊~
如果本站內容對你有幫助,歡迎使用 BFX Pay 加密貨幣 或 新台幣 贊助支持。
Polylang 居然把複製內容的功能把它列在 Pro 版才有,實在狠XD
這功能超級重要的說,網站建置的過程一定是先已預設語言下去處理,但要開始建置其他語系的時候,通常也是把預設語系的內容先搬過去在考慮翻譯問題。
內建的功能有提供「建立一個空白的對應語系內容頁面(Post, Page..)」,如下圖的「+」,很不錯的功能對吧~ 但複製過去是「空白」的啊,跟預想差很多(腦補應該是連這頁內容一整個都複製過去吧?)
好吧,不過這困擾一定不是我有,果然隨便一找就有大大分享作法了!
主題 functions.php 修正
方法參考:Make Polylang WordPress plugin copy the content from the original post
技術面上就是抓 GET 參數,把 Post ID 的內容複製到新的這篇,方法如下。(貼到主題下的 functions.php 中)
// 確保複製過去帶入預設內容
function mxp_editor_content( $content ) {
// Polylang 會帶入 'from_post' 這組 GET 參數
if ( isset( $_GET['from_post'] ) ) {
$my_post = get_post( $_GET['from_post'] );
if ( $my_post )
return $my_post->post_content;
}
return $content;
}
add_filter( 'default_content', 'mxp_editor_content' );
上面這組是複製內容,下面是複製標題。
// 確保複製過去時帶入預設標題
function mxp_editor_title( $title ) {
// Polylang 會帶入 'from_post' 這組 GET 參數
if ( isset( $_GET['from_post'] ) ) {
$my_post = get_post( $_GET['from_post'] );
if ( $my_post )
return $my_post->post_title;
}
return $title;
}
add_filter( 'default_title', 'mxp_editor_title' );
Polylang Copy Content 外掛
如果選擇使用外掛的話處理效果如上方兩組一樣,參考外掛的 Github。
下載釋出的外掛檔案,上傳到後台,啟用即可~