WordPress 페이지/게시물을 쉽게 복제하는 방법
게시 됨: 2021-11-05
페이지 또는 게시물의 기존 콘텐츠를 복제하는 것은 많은 상황에서 유용할 수 있습니다. 메인 포스트/페이지를 템플릿으로 사용하여 빠르게 작업을 완료할 수 있습니다. 같은 페이지/포스트의 내용을 다시 작성해야 한다면 시간이 얼마나 들까요?
글쎄, 나는 그것을 상상할 수 없습니다. 고맙게도 WordPress 페이지/게시물에 콘텐츠를 복제하는 방법이 있습니다. 이 게시물에서는 WordPress 페이지/게시물을 즉시 복제하는 방법을 보여 드리겠습니다.
그럼 시작하겠습니다.
- WordPress 페이지/게시물을 복제하는 이유는 무엇입니까?
- 플러그인이 있는 WordPress의 중복 콘텐츠
- 플러그인이 없는 WordPress 중복 페이지/게시물
- 마지막 단어
WordPress 페이지/게시물을 복제하는 이유는 무엇입니까?
페이지 또는 게시물에 새로운 변경 사항을 가져올 때 페이지/게시물을 빠르게 복제해야 할 수도 있습니다.
예를 들어 섹션이 많은 판매 페이지가 있습니다. 이제 다른 제품에 대해 동일한 판매 페이지를 다시 만들어야 합니다. 어떻게 하시겠습니까? 전체 페이지를 다시 만드시겠습니까?
당연히 아니지. 복제하면 똑같은 페이지를 얻을 수 있습니다. 바로 작업을 시작하고 시간을 절약할 수 있습니다. 두 가지 방법으로 WordPress 페이지/게시물을 복제할 수 있습니다. 1. 플러그인이 있는 경우, 2. 플러그인이 없는 경우.
플러그인이 있는 WordPress의 중복 콘텐츠
Duplicate Page, Post Duplicator, Duplicate page 및 Post, Page, Any Custom Post와 같은 몇 가지 플러그인이 있습니다. WordPress 페이지/게시물을 즉시 복제하는 데 도움이 됩니다. 그러나 가장 인기있는 것은 Yoast Duplicate Post입니다.
먼저 WordPress 플러그인 디렉토리에서 Yoast Duplicate Post 플러그인을 설치하고 활성화합니다.
대시보드에서 게시 -> 모든 게시물로 이동합니다. (페이지를 복제하려면 페이지 -> 모든 페이지로 이동)
이제 게시물에 커서를 올리면 '복제 및 새 초안'이라는 두 가지 새로운 옵션이 표시됩니다.
이제 복제 버튼을 클릭하여 게시물을 복제합니다.
그러나 클론을 생성하고 즉시 포스트 에디터에서 열고 싶다면 '새 초안' 버튼을 클릭하세요.
플러그인이 없는 WordPress 중복 페이지/게시물
설치된 플러그인의 수를 늘리고 싶지 않다면 이 방법을 따를 수 있습니다. 매우 간단합니다. 일부 코드를 function.php 파일에 복사하면 WordPress 페이지/게시물을 매우 쉽게 복제할 수 있습니다.
참고: WordPress 파일을 편집하기 전에 먼저 웹사이트를 백업하는 것이 좋습니다.
먼저 모양 -> 테마 편집기로 이동하여 '테마 기능'을 클릭합니다. 이제 다음 코드를 복사하여 여기에 붙여넣습니다.
/* * Function for post duplication. Dups appear as drafts. User is redirected to the edit screen */ function rd_duplicate_post_as_draft(){ global $wpdb; if (! ( isset( $_GET['post']) || isset( $_POST['post']) || ( isset($_REQUEST['action']) && 'rd_duplicate_post_as_draft' == $_REQUEST['action'] ) ) ) { wp_die('No post to duplicate has been supplied!'); } /* * Nonce verification */ if ( !isset( $_GET['duplicate_nonce'] ) || !wp_verify_nonce( $_GET['duplicate_nonce'], basename( __FILE__ ) ) ) return; /* * get the original post id */ $post_id = (isset($_GET['post']) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) ); /* * and all the original post data then */ $post = get_post( $post_id ); /* * if you don't want current user to be the new post author, * then change next couple of lines to this: $new_post_author = $post->post_author; */ $current_user = wp_get_current_user(); $new_post_author = $current_user->ID; /* * if post data exists, create the post duplicate */ if (isset( $post ) && $post != null) { /* * new post data array */ $args = array( 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_author' => $new_post_author, 'post_content' => $post->post_content, 'post_excerpt' => $post->post_excerpt, 'post_name' => $post->post_name, 'post_parent' => $post->post_parent, 'post_password' => $post->post_password, 'post_status' => 'draft', 'post_title' => $post->post_title, 'post_type' => $post->post_type, 'to_ping' => $post->to_ping, 'menu_order' => $post->menu_order ); /* * insert the post by wp_insert_post() function */ $new_post_id = wp_insert_post( $args ); /* * get all current post terms ad set them to the new post draft */ $taxonomies = get_object_taxonomies($post->post_type); // returns array of taxonomy names for post type, ex array("category", "post_tag"); foreach ($taxonomies as $taxonomy) { $post_terms = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'slugs')); wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false); } /* * duplicate all post meta just in two SQL queries */ $post_meta_infos = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id"); if (count($post_meta_infos)!=0) { $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) "; foreach ($post_meta_infos as $meta_info) { $meta_key = $meta_info->meta_key; if( $meta_key == '_wp_old_slug' ) continue; $meta_value = addslashes($meta_info->meta_value); $sql_query_sel[]= "SELECT $new_post_id, '$meta_key', '$meta_value'"; } $sql_query.= implode(" UNION ALL ", $sql_query_sel); $wpdb->query($sql_query); } /* * finally, redirect to the edit post screen for the new draft */ wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_post_id ) ); exit; } else { wp_die('Post creation failed, could not find original post: ' . $post_id); } } add_action( 'admin_action_rd_duplicate_post_as_draft', 'rd_duplicate_post_as_draft' ); /* * Add the duplicate link to action list for post_row_actions */ function rd_duplicate_post_link( $actions, $post ) { if (current_user_can('edit_posts')) { $actions['duplicate'] = '<a href="' . wp_nonce_url('admin.php?action=rd_duplicate_post_as_draft&post=' . $post->ID, basename(__FILE__), 'duplicate_nonce' ) . '" title="Duplicate this item" rel="permalink">Duplicate</a>'; } return $actions; } add_filter( 'post_row_actions', 'rd_duplicate_post_link', 10, 2 );
파일 업데이트를 잊지 마십시오.
위의 코드는 게시물 복제에 사용할 것입니다. 페이지를 복제하려면 마지막 줄을 다음 코드로 바꾸면 됩니다.
add_filter('page_row_actions', 'rd_duplicate_post_link', 10, 2);
마지막 단어
이제 WordPress 페이지/게시물을 쉽게 복제할 수 있기를 바랍니다. 플러그인을 사용하는지 여부는 중요하지 않습니다. 두 가지 방법 모두에서 동일한 결과를 얻을 수 있습니다. 질문이나 제안 사항이 있으면 아래 의견란을 통해 알려주십시오.