• 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細

このWikiはいつでも誰でも編集できます

「テンプレートタグ/get permalink」の版間の差分

提供: WordPress Codex 日本語版
移動先: 案内検索
7行目: 7行目:
 
* 出力例: <code><nowiki><p><a href="http://example.com/index.php?p=5">記事ID5へのリンク</a></p></nowiki></code>
 
* 出力例: <code><nowiki><p><a href="http://example.com/index.php?p=5">記事ID5へのリンク</a></p></nowiki></code>
  
[[en:Template Tags/get_permalink]]
+
== 説明 ==
 +
 
 +
Returns the [[Glossary#Permalink|permalink]] to a post or page for use in [[Glossary#PHP|PHP]]. It does NOT display the permalink and can be used outside of [[The Loop]]. On failure returns <code>false</code>.
 +
 
 +
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
 +
 
 +
== 使い方 ==
 +
 
 +
<?php $permalink = get_permalink( $id ); ?>
 +
 
 +
== 引数 ==
 +
 
 +
{{Parameter|$id|mixed|The integer ID for a post or page, or a post object|optional|The current post ID, when used in [[The Loop]].}}
 +
{{Parameter|$leavename|bool|Whether to keep the post name or page name. When set to <tt>true</tt>, a structural link will be returned, rather than the actual URI. Example: <tt><nowiki>http://www.example.com/%postname%</nowiki></tt> instead of <tt><nowiki>http://www.example.com/my-post</nowiki></tt>|optional|<tt>false</tt>}}
 +
 
 +
== 戻り値 ==
 +
; (string|bool) : The permalink URL, or <tt>false</tt> on failure (if the page doesn't exist).
 +
 
 +
== 用例 ==
 +
 
 +
<a href="<?php echo get_permalink( 268 ); ?>">My link to a post or page</a>
 +
 
 +
=== Default Usage ===
 +
 
 +
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:
 +
<?php echo get_permalink(); ?>
 +
 
 +
=== Link to Specific Post ===
 +
 
 +
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.
 +
 
 +
&lt;ul&gt;
 +
&lt;li&gt;MyBlog info:
 +
    &lt;ul&gt;
 +
    &lt;li&gt;&lt;a href="<?php echo get_permalink(1); ?>"&gt;About MyBlog&lt;/a&gt;&lt;/li&gt;
 +
    &lt;li&gt;&lt;a href="<?php echo get_permalink(10); ?>"&gt;About the owner&lt;/a&gt;&lt;/li&gt;
 +
    &lt;/ul&gt;
 +
&lt;/li&gt;
 +
&lt;/ul&gt;
 +
 
 +
=== Pass in a post object instead of an ID ===
 +
This shows how you can you can get the permalink with the page title instead of the ID.
 +
<pre><a href="<?php echo esc_url( get_permalink( get_page_by_title( 'Monthly Events' ) ) ); ?>">Monthly Events</a></pre>
 +
 
 +
== 変更履歴 ==
 +
 
 +
Since: 1.0.0
 +
 
 +
== ソースファイル ==
 +
 
 +
<tt>get_permalink()</tt> is located in {{Trac|wp-includes/link-template.php}}.
 +
 
 +
== 関連項目 ==
 +
 
 +
{{Permalink Tags}}
 +
 
 +
{{原文|Function Reference/get_permalink|132252}}<!-- 17:17, 18 June 2013 JD55 版 -->
 +
 
 +
{{Tag Footer}}

2014年5月17日 (土) 16:20時点における版

  • 書式: <?php get_permalink(id); ?>
  • 説明: 記事のパーマリンクをPHPの値として返す。実際のページ内には表れないが、PHPコマンドや関数を使うことにより出力させることもできる。
  • 位置: ループ内・外
  • 引数:
    • id (整数)- 記事の数字ID。ループ内で使用した場合、デフォルト値は表示中記事のID。
  • コード記述例: <p><a href="<?php echo get_permalink(5); ?>">記事ID5へのリンク</a></p>
  • 出力例: <p><a href="http://example.com/index.php?p=5">記事ID5へのリンク</a></p>

説明

Returns the permalink to a post or page 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

使い方

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

引数

$id
mixed) (optional) The integer ID for a post or page, or a post object
初期値: The current post ID, when used in The Loop.
$leavename
bool) (optional) Whether to keep the post name or page name. When set to true, a structural link will be returned, rather than the actual URI. Example: http://www.example.com/%postname% instead of http://www.example.com/my-post
初期値: false

戻り値

(string|bool) 
The permalink URL, or false on failure (if the page doesn't exist).

用例

<a href="<?php echo get_permalink( 268 ); ?>">My link to a post or page</a>

Default Usage

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:
<?php echo get_permalink(); ?>

Link to Specific Post

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>

Pass in a post object instead of an ID

This shows how you can you can get the permalink with the page title instead of the ID.

<a href="<?php echo esc_url( get_permalink( get_page_by_title( 'Monthly Events' ) ) ); ?>">Monthly Events</a>

変更履歴

Since: 1.0.0

ソースファイル

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

関連項目

get_permalink(), the_permalink(), post_permalink(), permalink_anchor(), permalink_single_rss()


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


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