[WordPress] 外掛分享: Simple Permalink

首頁外掛目錄 › Simple Permalink
30+
安裝啟用
★★★★★
5/5 分(1 則評價)
4716 天前
最後更新
問題解決
WordPress 3.0+ v1.0.1 上架:2012-05-28

內容簡介

這個外掛會根據 ID 使用 [permalink] 短碼來檢索頁面或文章的永久連結網址。

這個外掛的目的是什麼?

在使用 WordPress 建立自己的網站時,我開始注意到我喜歡在文章中連結到其他文章。但我總是改變我的想法,更改頁面或文章別名,並改變我的永久連結。當我必須回去更改我放置連結的位置時,這很煩人。

這個外掛相當簡單。它只是根據 WordPress 獨特的數值 ID 檢索頁面或文章的網址,而這個 ID 永遠不會變。對我個人而言,每次在我的網站內連結到另一個頁面或文章時使用 [permalink] 短碼會讓我的生活變得更輕鬆,因為我不用擔心網址會變化。此外,當我將我的網站從本地開發服務器移動到網際網路伺服器時,我不用擔心任何這些連結。

無論如何,我想,“為什麼不分享呢?”-- 我總是將這個代碼片段粘貼到所有個人網站主題中。

但是,請記住,此外掛對於像我一樣總是在編輯頁面和文章時在HTML選項卡下工作的人來說會更加有用。如果您正在尋找一個類似的短碼,可以為您構造整個HTML連結,請查找由 Justin Tadlock 創建的此外掛程式。

使用範例

由於此外掛只是檢索文章或頁面的網址,因此您需要以您通常的方式格式化標準的HTML連結。然後,取代手動寫入文章或頁面的網址,使用 [permalink] 短碼來檢索它。在裡面,您引用 WordPress 的數值 ID 來取得文章或頁面的網址。

<a href="[permalink id="123"]">Your Text</a>

<a href="[permalink id="123"]" title="Your Link Title">Your Text</a>

<a href="[permalink id="123"]#some_section_of_page">Your Text</a>

擴展使用範例

在 v1.0.1 中,我新增了可選功能,允許您使用頁面別名來引用您正在嘗試檢索永久連結。

<a href="[permalink slug="your-page"]">Your Text</a>

如果您引用的不是頁面,您需要使用可選的“post_type”參數來指定文章類型。

<a href="[permalink slug="your-post" post_type="post"]">Your Text</a>

如果您能使用文章 ID,那麼以這種方式檢索永久連結將消耗較少的伺服器資源。

那麼為什麼要使用別名?為什麼不總是使用 ID?個人而言,我添加了這個功能給自己。當我為我的 WordPress 主題建立示範網站時,我總是導入很多彼此之間的相同頁面,這些頁面互相內部鏈接。如您所知,在不同網站之間導入頁面和文章時,ID 通常會變化。通過使用此短碼並引用頁面/文章別名,當我將頁面導入/導出到不同的網站時,我可以保持 URL 不變。

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.0.1) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Simple Permalink」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

This plugin retrieves the permalink URL for a page or post based on the ID with the shortcode [permalink].
What’s the point of this plugin?
In creating my own sites with WordPress, I started noticing that I like to link to articles within other articles. Then I’m always changing my mind about stuff, messing around with page/post slugs, and screwing with my permalinks. It’s very annoying to then have to go back and change links wherever I placed them.
This plugin is pretty simple. It just retrieves the URL of a page or post based on WordPress’s unique, numerical ID for it, which never changes. For me personally, using the [permalink] shortcode every time I link to another page or post within my site makes life easier because I don’t have to worry about the URL changing. Also, when I move my site from my local dev server to the live web server, I don’t have to worry about any of these links.
Anyways, I thought what the heck, why not share? — I keep pasting this code snippet in all my personal website themes anyway.
However, keep in mind this plugin will be more useful for people like me who are always working under the HTML tab when editing pages and posts. If you’re looking for a similar shortcode that constructs the entire HTML link for you, check out this plugin by Justin Tadlock.
Usage Examples
Since all this plugin does is retrieve the URL to the post or page, you need to format a standard HTML link in whatever way you normally would. Then, instead manually writing in the post or page’s URL, you retrieve it with the [permalink] shortcode. Inside, you reference the WordPress’s numeric ID for the post or page.
Your Text

Your Text

Your Text

Extended Usage Examples
In v1.0.1, I added the optional feature to allow you to use a page’s slug to reference the permalink you’re trying to retrieve.
Your Text

If you’re referencing anything other than a page, you need to specify the post type with the optional “post_type” parameter.
Your Text

If you can use the Post ID, it will consume less resources on your server to retrieve the permalinks that way.
So why use the slug at all? Why not just always use the ID? Well personally, I added this in for myself. When I setup demo websites for my WordPress themes, I’m always importing many of the same pages that innerlink with eachother. As you know, when importing pages and posts between different websites, ID’s will generally change. By using this shortcode and referencing page/post slugs, I can keep URL’s intact when I’m importing/exporting pages to different websites.

延伸相關外掛

文章
Filter
Apply Filters
Mastodon