Last active
August 28, 2015 06:29
-
-
Save semicolon/4017c95a849c7c812b54 to your computer and use it in GitHub Desktop.
Movable Type のデータを PHP+SQL で取得する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Movable Type が設置されているディレクトリのパス | |
$basepath = '/path/to/MT'; | |
// mt-config.cgi のファイル名 | |
$cfg_file = 'mt-config.cgi'; | |
// include_path に Movable Type のライブラリディレクトリを追加します | |
set_include_path(get_include_path() . PATH_SEPARATOR . $basepath . '/php' . PATH_SEPARATOR . $basepath . '/php/extlib' . PATH_SEPARATOR . $basepath . '/MT/php/lib'); | |
// PHP で Movable Type を操作するためのライブラリを読み込みます | |
require_once('mt.php'); | |
// MTオブジェクトのインスタンスを作成します | |
$mt = MT::get_instance(null, $cfg_file); | |
// カテゴリIDが「10」のエントリーを最新10件取得する SQL 文です | |
$sql = "SELECT * from mt_entry WHERE entry_status=2 AND entry_id IN "; | |
$sql .= "(SELECT placement_entry_id FROM mt_placement WHERE placement_category_id=10) "; | |
$sql .= "ORDER BY entry_authored_on DESC LIMIT 10 OFFSET 0;"; | |
// SQL を実行し、レコードを取得します | |
$records = $mt->db()->execute($sql); | |
// 取得したレコードを表示します | |
print('<ul>'); | |
foreach ($records as $rec) { | |
$blog_id = $rec['entry_blog_id']; | |
// MT オブジェクトに blog_id をセットして初期化します | |
$mt->init($blog_id, $cfg_file); | |
// エントリーのパーマリンクを取得します | |
$url = $mt->db()->entry_link($r['entry_id'], 'Individual'); | |
// エントリーの公開日時を取得します | |
$date = date("Y年m月d日", strtotime($r['entry_authored_on'])); | |
// エントリーの情報を表示します | |
print('<li><a href="' . $url . '">' . strip_tags($r['entry_title']) . '</a>(' . $date . ')</li>'; | |
} | |
print('</ul>'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment