wordpress文章转Git
最近把wordpress文章转到Git有些格式还是有问题有时间在整理吧
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| $dbms = 'mysql'; $host = 'localhost'; $dbName = 'ioqx'; $user = 'root'; $pass = 'root'; $dsn = "$dbms:host=$host;dbname=$dbName"; try { $dbh = new PDO($dsn, $user, $pass); echo "连接成功\n"; $sql = "SELECT wp.id,wp.post_parent,wp.post_date,wp.post_modified,wp.post_title,wp.post_content,wt.`name` FROM wp_posts wp LEFT JOIN wp_term_relationships wtr ON wp.id=wtr.object_id LEFT JOIN wp_terms wt ON wtr.term_taxonomy_id=term_id WHERE wp.post_status='publish' AND wt.`name` != ''"; foreach ($dbh->query($sql) as $row) { echo "生成id:{$row['id']}\n"; $title =trim($row['post_title']) ; $startDate = $row['post_date']; $modifiedDate = $row['post_modified']; $tags = $row['name']; $content = $row['post_content'];
$md = <<<EOF --- title: $title date: $startDate updated: $modifiedDate categories: $tags tags: $tags --- $content EOF; file_put_contents('/Users/zhangzecheng/code/github/myBlog/source/_posts/' . $title . '.md', $md); } $dbh = null; echo '已生成完毕'; } catch (PDOException $e) { die ("Error!: " . $e->getMessage() . "\n"); }
|