본문 바로가기
IT

고전 편집기 vs. 블록 에디터

by Oh.mogilalia 2023. 10. 19.

워드프레스에서는 블록 에디터가 기본 편집기로 사용되고 있습니다. 단축키를 익혀서 활용하면 능률적으로 글 작성이 가능합니다.

HTML Import 2 플러그인을 사용하여 티스토리 데이터를 임포트하면 고전 편집기에서 글이 편집됩니다. 이는 HTML 태그 때문인데요. 원하는 경우 "블록으로 변환"이 가능합니다. 하지만 HTML 태그 때문에 제대로 변환되지 않을 것입니다. 글을 수정해야 하는 경우 아래의 단계에 따라 블록으로 변환이 가능합니다. (이 단계는 굳이 할 필요가 없지만 글을 블록 에디터에서 수정하고 싶은 경우에 참고하세요.)

① 글 편집 화면에서 Ctlr+Shift+Alt+M 단축키를 눌러 HTML 모드로 전환합니다.

② 맨 위의 <div class="contents_style">과 맨 아래의 "</div>"를 삭제합니다.

③ Ctlr+Shift+Alt+M 단축키를 눌러 비주얼 보기로 전환합니다.

④ 글 본문을 선택하고 상단의 블록으로 변환 버튼을 클릭하면 정상적으로 블록으로 변환될 것입니다.

임포트 후에 모든 글에서 불필요한 HTML 태그 제거하기

임포트 후에 위의 방법과 같이 개별 글에서 <div class="contents_style">...</div> 태그를 제거하는 방법 대신 모든 글에서 일괄적으로 이 태그를 삭제하는 것도 가능합니다.

phpMyAdmin 등의 데이터베이스 툴을 사용하여 DB에 접속하여 다음 명령을 수행하면 <div class="contents_style"> 태그가 삭제됩니다.

$ root@Gugeosigan:/# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 697
Server version: 8.0.34-0ubuntu0.20.04.1 (Ubuntu)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mogibu_wp          |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.45 sec)

mysql> use mogibu_wp
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------------------+
| Tables_in_mogibu_wp        |
+----------------------------+
| wp_actionscheduler_actions |
| wp_actionscheduler_claims  |
| wp_actionscheduler_groups  |
| wp_actionscheduler_logs    |
| wp_commentmeta             |
| wp_comments                |
| wp_e_events                |
| wp_links                   |
| wp_options                 |
| wp_postmeta                |
| wp_posts                   |
| wp_term_relationships      |
| wp_term_taxonomy           |
| wp_termmeta                |
| wp_terms                   |
| wp_usermeta                |
| wp_users                   |
| wp_wpforms_payment_meta    |
| wp_wpforms_payments        |
| wp_wpforms_tasks_meta      |
+----------------------------+
20 rows in set (0.01 sec)

mysql> UPDATE wp_posts SET post_content = REPLACE (post_content, '<div class="contents_style">', '');
Query OK, 9587 rows affected (12.90 sec)
Rows matched: 24960  Changed: 9587  Warnings: 0

mysql>  flush privileges;
Query OK, 0 rows affected (0.37 sec)

mysql> quit;
Bye
root@Gugeosigan:/# exit
mogibu@Gugeosigan:~$
--------------------------------------------------------
.
각 포스트의 끝에 있는 </div>를 제거하는 것은 간단하지 않습니다. 다음과 같은 PHP 파일을 만들어서 실행하면 각 블로그 글의 끝에 위치한 </div>가 삭제됩니다.

tistory_div.php 내용

<?php 

require_once('wp-load.php');
// Get global database object
global $wpdb;

// Query to get all posts
$posts = $wpdb->get_results("SELECT ID, post_content FROM {$wpdb->prefix}posts WHERE post_type='post'");

// Loop through each post
foreach ($posts as $post) {
    // Check if content ends with '</div>'
    if (substr($post->post_content, -6) === '</div>') {
        // Remove '</div>' at the end of the content
        $new_content = substr($post->post_content, 0, -6);

        // Update the post in the database
        $wpdb->update(
            "{$wpdb->prefix}posts",
            ['post_content' => $new_content],
            ['ID' => $post->ID]
        );
    }
}

?>
-----------------------------------------------------------

예를 들어, wp-config.php 파일이 위치한 곳(/home/mogibu/www)에 tistory.php 파일을 만들고, 위의 코드를 추가한 다음, 실행할 수 있습니다. 한 번만 실행하고 PHP 파일은 삭제하도록 합니다.

크롬 브라우저를 열고 주소창에 입력

wp.mogibu.kro.kr/tistory_div.php 엔터

꽤 오랜 시간 동안 진행 중

아, 클났다. 아까 작업한 거 백업 못했네. db는 좀전에 백업했고...

잘 되얄 텐데...

'IT' 카테고리의 다른 글

phpMyAdmin 5.2.1 업그레이드  (0) 2023.10.21
mysql 명령어  (0) 2023.10.19
Ubuntu 서버 백업  (0) 2023.10.19
우분투 서버 나눔고딕 폰트 설치  (0) 2023.10.19
Tistory 백업과 Wordpress로 옮기기  (0) 2023.10.15