get permalink

Sponsored Link

PHPで使用するために投稿のパーマリンクを返します。パーマリンクを表示せず、ループの外で使用することができます。失敗した場合はfalseを返します。

Sponsored Link

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

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

Note that 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です。
デフォルト:ループで使用されていた時、現在のポストのIDです。

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

デフォルトの使用方法

現在の投稿のためのパーマリンク(ループ内で使用される)です。タグがパーマリンクを表示しないように、例では、PHPのechoコマンドを使用しています。

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

この投稿のパーマリンクです:<br />
<?php echo get_permalink(); ?>

特定の投稿へのリンク

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

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>

現在のページへのリンク

LOOP外で使用することができます。

This can also be used outside the LOOP

<a href="<?php echo esc_url( wp_logout_url( $_SERVER&#91;'REQUEST_URI'&#93; ) ); ?>">Log out</a>

変更ログ

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