
內容簡介
這個外掛可使用短代碼 by id 或 slug(引用文章)輕輕鬆鬆地建立到另一個文章的連結,除非被覆寫,否則連結文字會是文章的標題。
在編寫文章時,您可以按 ID 引用其他文章,像這樣:
[post2post id="20"]
或按文章縮略名/名稱引用,像這樣:
[post2post id="hello-world"]
在網站上查看時,引用文章的 post-to-post 連結標籤會被替換為向您引用的文章的永久鏈接。默認情況下,鏈接的文本將是引用文章的標題,結果會像這樣:
"<a href="http://example.com/archives/2005/04/01/hello-world/" title="Hellow World!">Hello World!</a>"
您可以通過指定 post-to-post 連結標籤的 text="" 屬性和值,自定義鏈接文本:
Check out [post2post id="hello-world"]my first post[/post2post].
這會得到下面的結果:
Check out "<a href="http://example.com/archives/2011/07/01/hello-world/" title="Hello World!">my first post</a>"。
該插件通過 WordPress 管理員界面的 設置 -> Post2Post 提供自己的管理選項頁面 。在這裡,您可以定義要出現在每個文章替換之前和/或之後的文本,以及是否要啟用舊標籤支持。該插件的管理頁面還提供了一些文檔。
鏈接: 外掛主頁 | 外掛目錄頁 | GitHub | 作者主頁
範例
這些都是引用您博客上另一篇文章的有效方式。
[post2post id="25"]
[post2post id="25"/]
`[post2post id=”the-best-post-ever”]
`[post2post id=”the-best-post-ever”/]
假設以上所有方式都用於引用同一篇文章,則 post-to-post 縮寫的替換會是:
"<a href="http://example.com/2011/07/01/the-best-post-ever" title="The Best Post Ever!">The Best Post Ever!</a>"
對於以上任何一個,您還可以選擇將短代碼包圍在文本周圍。如果定義了這樣的文本,則該文本將用作鏈接文本,而不是引用文章的標題。
[post2post id="25"]this post[/post2post]
[post2post id="blog-anniversary"]Congratulate me![/post2post]
其中第一個會產生:
"<a href="http://example.com/2011/07/01/the-best-post-ever" title="The Best Post Ever!">this post</a>"
您還可以選擇可選定義生成鏈接之前和之後顯示的文本。默認情況下,這些是引言。
`[post2post id=”25″ before=” ” after=”!”]
結果如下:
<a href="http://example.com/2011/07/01/the-best-post-ever" title="The Best Post Ever!">this post</a>!<h3>Legacy</h3>
舊語法 — 除非您使用的是 v3.0 以前的版本,否則不建議使用 — 允許您使用偽短代碼語法或 HTML 註釋語法按 ID 引用其他文章,如下所示:
[post="20"] 或 `<!--post="20"-
外掛標籤
開發者團隊
原文外掛簡介
Easily create a link to another post using a shortcode to reference the post by id or slug; the link text is the post’s title, unless overridden.
When writing your posts, you can refer to other posts either by ID, like so:
[post2post id="20"]
or by the post slug/name, like so:
[post2post id="hello-world"]
When viewed on your site, the post-to-post link tag is replaced with a permalink to the post you’ve referenced. By default, the text of the link will be the referenced post’s title, resulting in something like:
"Hello World!"
You can optionally customize the link text by specifying a text="" attribute and value to the post-to-post link tag:
Check out [post2post id="hello-world"]my first post[/post2post].
Which yields:
Check out "my first post".
The plugin provides its own admin options page via Settings -> Post2Post in the WordPress admin. Here you can define text that you want to appear before and/or after each post-to-post substitution, and if you want to enable legacy tag support. The plugin’s admin page also provides some documentation.
Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage
Examples
These are all valid ways to reference another of your posts on the same blog.
[post2post id="25"]
[post2post id="25"/]
`[post2post id=”the-best-post-ever”]
`[post2post id=”the-best-post-ever”/]
Assuming all of the above were used to reference the same post, the replacement for the post-to-post shortcut would be:
"The Best Post Ever!"
For any of the above you can also optionally wrap the shortcode around text. If so defined, that text will be used as the link text as opposed to the referenced post’s title.
[post2post id="25"]this post[/post2post]
[post2post id="blog-anniversary"]Congratulate me![/post2post]
The first of which would produce:
"this post"
You can also optionally definte the text that appears before and after the generated links. By default these are quotes.
`[post2post id=”25″ before=” ” after=”!”]
Yields:
this post!
Legacy
The legacy syntaxes — which are disabled by default and not recommended for use unless you’ve used version of the plugin earlier than v3.0 — allow you to refer to other posts by ID using a pseudo-shortcode syntax or an HTML comment syntax, like so:
[post="20"] or ``
or by the post slug/name, like so:
[post="hello-world"] or `.`
The HTML comment notation was the original syntax employed by earlier versions of this plugin (pre v2.0). While it is still supported, it is no longer the primary and recommended syntax. The pseudo-shortcode syntax was in use between v2.0 and v3.0 of the plugin.
NOTE: The HTML comment syntax notation does NOT play well with the visual (aka rich-text) editor in the WordPress admin.
Examples of old legacy syntax follow. Those that use the pseudo-shortcode syntax (i.e. [post=25]) only work if you’ve checked “Enable legacy pseudo-shortcode tag support?”. Those that use HTML comment notation (i.e. ) only work if you’ve checked “Enable legacy HTML comment-style tag support?”.
[post=25]
[post="25"]
[post = "25"]
[post='25']
[post = '25']
[post="the-best-post-ever"]
[post = "the-best-post-ever"]
[post='the-best-post-ever']
[post = 'the-best-post-ever']
NOTE: Only activate the legacy mode(s) that apply to your use of older versions of the plugin. If you started using the plugin at v3.0 or later, you should not activate either legacy mode.
Filters
The plugin exposes one filter for hooking. Typically, customizations utilizing this hook would be put into your active theme’s functions.php file, or used by another plugin.
c2c_post2post_shortcode (filter)
The ‘c2c_post2post_shortcode’ hook allows you to define an alternative to the default shortcode tag. By default the shortcode tag name used is ‘post2post’. It is recommended you only utilize this filter before making use of the plugin’s shortcode in posts and pages. If you change the shortcode tag name, then any existing shortcodes using an older name will no longer work (unless you employ further coding efforts).
Arguments:
$shortcode (string)
Example:
/**
* Use a shorter shortcode: i.e. [p2p id="32"]
*
* @param string $shortcode The default shortcode name.
* @return string The new shortcode name.
*/
function change_post2post_shortcde( $shortcode ) {
return 'p2p';
}
add_filter( 'c2c_post2post_shortcode', 'change_post2post_shortcde' );
