get_permalink

Sponsored Link

PHPで使用するために記事のパーマリンクを返します。パーマリンクを表示せずに、ループ外で使用する事が出来ます。

Returns the permalink to a post for use in PHP. It does NOT display the permalink and can be used outside of The Loop.

IDパラメーターなしに記事ページ(インデックス、アーカイブなど)をループ外で使用した時は注意してください。現在のページのパーマリンクがないループ内の最終記事のURLを返すでしょう。参照:http://core.trac.wordpress.org/ticket/9963

Note the when used outside The Loop on a posts page (index, archive, etc.) without the ID parameter, it will return the URL of the last post in The Loop, not the permalink for the current page. See: http://core.trac.wordpress.org/ticket/9963

get_permalinkのテンプレートタグ使用方法

<?php $permalink = get_permalink( $id ); ?> 

get_permalinkのパラメーター

$id

(integer) (optional) 記事のための数値IDです。

(integer) (optional) The numeric ID for a post.

デフォルト:現在の記事IDがループ内で使用している時です。

Default: The current post ID, when used in The Loop.

デフォルトの使い方

現在の記事(ループ内で使用)のパーマリンクです。タグはパーマリンクを表示しないように、PHPエコーコマンドを使用する例です。

The permalink for current post (used within The Loop). As the tag does not display the permalink, the example uses the PHP echo command.

Permalink for this post:<br />
<?php echo get_permalink(); ?>

特定の記事にリンクする方法

情報リスト内にハイパーテキストリンクとして2つの特定記事(ポストID1と10)のパーマリンクを返します。上記のように、タグはパーマリンクを表示するためにPHPのエコーコマンドを使用します。

Returns the permalinks of two specific posts (post IDs 1 and 10) as hypertext links within an informational list. As above, tag uses the PHP echo command to display the permalink.

<ul>
<li>MyBlog info:
   <ul>
   <li><a href="<?php echo get_permalink(1); ?>">About MyBlog</a></li>
   <li><a href="<?php echo get_permalink(10); ?>">About the owner</a></li>
   </ul>
</li>
</ul>

変更ログ

Since: 1.0.0

ソースファイル

get_permalink()はwp-includes/link-template.php内に位置しています。

get_permalink() is located in wp-includes/link-template.php.

関連テンプレートタグ

get_permalink, the_permalink, post_permalink, permalink_anchor, permalink_single_rss

Sponsored Link