当サイト、Codex 日本語版は今後積極的な更新は行わない予定です。後継となる新ユーザーマニュアルは、https://ja.wordpress.org/support/ にあります。
万が一、当サイトで重大な問題を発見した際などは、フォーラムWordSlack #docs チャンネルでお知らせください。</p>

テンプレートタグ/the ID

提供: WordPress Codex 日本語版
< テンプレートタグ
2016年10月6日 (木) 21:16時点におけるGblsm (トーク | 投稿記録)による版 (get_the_ID() のリンク先を修正。)

(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

説明

現在の投稿の ID を表示します。必ずループの中で使用してください。

注: このテンプレートタグは投稿で ID を表示するために使用します。ID を取得したい場合は get_the_ID を使用します。

使い方

<?php the_ID(); ?>

パラメータ

なし

用例

基本的な使用方法

<p>投稿番号: <?php the_ID(); ?></p>

XHTML で 要素の id に投稿番号を使用する場合

投稿にユニークなアンカー ID を付与します:

<h3 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h3>

注: XHTML では要素の ID を数字から始めることはできません。the_ID() は数値を返しますので、上記の「post-<?php the_ID(); ?>」のようにテキスト+記事 ID という形式にする必要があります。

更新履歴

新規導入: 0.71

ソースファイル

the_ID()wp-includes/post-template.php にあります。

関連項目

投稿タグ: body_class(), next_image_link(), next_post_link(), next_posts_link(), post_class(), post_password_required(), posts_nav_link(), previous_image_link(), previous_post_link(), previous_posts_link(), single_post_title(), sticky_class(), the_category(), the_category_rss(), the_content(), the_content_rss(), the_excerpt(), the_excerpt_rss(), the_ID(), the_meta(), the_shortlink(), the_tags(), the_title(), the_title_attribute(), the_title_rss(), wp_link_pages(),


関数リファレンステンプレートタグ目次もご覧ください。


最新英語版: WordPress Codex » Function Reference/the_ID最新版との差分