[WordPress][Hack] 記事 ID を指定してその情報を取り出す

2006年12月21日 木曜日 05時12分
E-Mail This Post/Page Print This Post/Page

丁度プラグインなどを作り出してから、ほぼ無限大といっても良いほど拡がるそのカスタマイズのポテンシャルに気がつく一方で、その処理をさせるための操作する側;その個人に要求される情報の消化はその総量の数十倍以上に及ぶような気がしている。

ということで、その情報をちっぽけな脳みそに叩き込むために忘れないうちに書き留めておこう、っと。

次の関数は記事のIDがわかっていると、その記事の情報をリターンしてくれる。

記事のIDを取得するには、

PHP:
  1. global $wp_query;
  2. $thePostID = $wp_query->post->ID;

$thePostID にそのコードが実行されるときの記事番号がストアされる。

wp-includes/function.php line567

PHP:
  1. function get_postdata($postid) {
  2.     $post = &get_post($postid);
  3.  
  4.     $postdata = array (
  5.         'ID' => $post->ID,
  6.         'Author_ID' => $post->post_author,
  7.         'Date' => $post->post_date,
  8.         'Content' => $post->post_content,
  9.         'Excerpt' => $post->post_excerpt,
  10.         'Title' => $post->post_title,
  11.         'Category' => $post->post_category,
  12.         'post_status' => $post->post_status,
  13.         'comment_status' => $post->comment_status,
  14.         'ping_status' => $post->ping_status,
  15.         'post_password' => $post->post_password,
  16.         'to_ping' => $post->to_ping,
  17.         'pinged' => $post->pinged,
  18.         'post_name' => $post->post_name
  19.     );
  20.  
  21.     return $postdata;
  22. }

ということで、

PHP:
  1. print_r(get_postdata($thePostID));

とするとどうなるのかな?以下、結果。

Array
(
[ID] => 143
[Author_ID] => 2
[Date] => 2006-12-21 05:28:53
[Content] => 丁度プラグインなどを作り出してから、ほぼ無限大といっても良いほど拡がるそのカスタマイズのポテンシャルに気がつく一方で、その処理をさせるための操作する側;その個人に要求される情報の消化はその総量の数十倍以上に及ぶような気がしている。

ということで、その情報をちっぽけな脳みそに叩き込むために忘れないうちに書き留めておこう、っと。

次の関数は記事のIDがわかっていると、その記事の情報をリターンしてくれる。

記事のIDを取得するには、

PHP:
  1. global $wp_query;
  2. $thePostID = $wp_query->post->ID;

$thePostID にそのコードが実行されるときの記事番号がストアされる。

wp-includes/function.php line567

PHP:
  1. function get_postdata($postid) {
  2.     $post = &get_post($postid);
  3.  
  4.     $postdata = array (
  5.         'ID' => $post->ID,
  6.         'Author_ID' => $post->post_author,
  7.         'Date' => $post->post_date,
  8.         'Content' => $post->post_content,
  9.         'Excerpt' => $post->post_excerpt,
  10.         'Title' => $post->post_title,
  11.         'Category' => $post->post_category,
  12.         'post_status' => $post->post_status,
  13.         'comment_status' => $post->comment_status,
  14.         'ping_status' => $post->ping_status,
  15.         'post_password' => $post->post_password,
  16.         'to_ping' => $post->to_ping,
  17.         'pinged' => $post->pinged,
  18.         'post_name' => $post->post_name
  19.     );
  20.  
  21.     return $postdata;
  22. }

ということで、

PHP:
  1. print_r(get_postdata($thePostID));

とするとどうなるのかな?以下、結果。

global $wp_query;
$thePostID = $wp_query->post->ID;
print_r(get_postdata($thePostID));
?>

[Excerpt] =>
[Title] => [WordPress][Hack] 記事 ID を指定してその情報を取り出す
[Category] => 0
[post_status] => publish
[comment_status] => closed
[ping_status] => open
[post_password] =>
[to_ping] =>

[pinged] =>
http://member.blogpeople.net/tback/00935
[post_name] => wordpresshackid
)

Share This

この記事に関連する NEWS

この記事に関連するトピック

このエントリーへの Yahoogle Suggestions

Trackback this Post |

 

記事ヒット TOP 10

WordPress Tips from Social Bookmarks Jp

    There is no entries available for this category.

WordPress Tips from Social Bookmarks

    There is no entries available for this category.

WordPress Plugins from Social Bookmarks

    There is no entries available for this category.

Tag Cloud

admin Admin Drop Menus Admin Memo Admin Panel advanced drop menus array unique blog cron dabeya Dagon Design Sitemap Generator dropcap Edit N Place error Feedburner game google hack html HTML CSS Internet NEWS Permalink Redirect PHP phpBB2 plugin RSS scripts search stattraq template the content Ultimate Tag Warrior Web Management Windows XP Wordpress WP Plugins WPページ  拡張子 カスタマイズ カスタム関数 カテゴリー コード セキュリティ タグ トップページ トラックバック フィード 投稿 抜粋 日本語 時刻 時間 正規表現 表示 記事

サイト メニュー

Blogtimes image
ぱそずき :D)‐く © 2008
Close
E-mail It