內容簡介
Shortlinks 可以讓您輕鬆擷取 WordPress 貼文(post)、頁面(page)、分類(category)、文章標籤(post_tags)、附件(attachments)、自訂貼文類型(custom post types)以及自訂分類(custom taxonomies)的短網址(shortlink)。
預設情況下,WordPress 使用查詢字串來載入貼文、頁面、分類等等(例如:http://blog.aizatto.com/?page_id=3565),但當您啟用固定連結時,查詢字串會被 WordPress 重導規則隱藏。好看的 URL 很棒,但也使網站較不靈活。例如,變更文章的發布日期會變更其 URL。
即便我們無法控制其他人如何連結至我們的網站,但我們可以控制自己連結至我們內部網站的方式。
啟用固定連結時,預設情況下,當訪問 WordPress 的短網址時,WordPress 會將您重新導向至固定連結 URL。
如何運作
Shortlinks 連結至 WordPress Filter get_shortlink,以啟用所有 WordPress 類型的短網址。
您可以將 Shortlinks 移植至自己的佈景主題或外掛程式。
若要為貼文、頁面或自訂貼文類型返回短網址,其中 $id 代表 ID:
若要為分類返回短網址,其中 $id 代表分類 ID:
若要為自訂分類返回短網址,其中 $id 代表術語 ID,而 $taxonomy 代表自訂分類:
我為什麼要創建它
WordPress 預設支援短網址,但只允許使用者取得貼文的短網址。我認為這不足以滿足需求,因此我創建了此外掛程式以取得所有內容類型的短網址。
外掛標籤
開發者團隊
原文外掛簡介
Shortlinks allows you to easily retrieve the shortlink for your WordPress posts, pages, categories, post_tags, attachments, custom post types, and custom taxonmies.
By default, WordPress uses links a query string ( ie: http://blog.aizatto.com/?page_id=3565 ) to load up your posts, pages, categories, etc. But when you enable permalinks, the query string is hidden by the WordPress rewrite rules. Having pretty urls is great, but also makes the website less flexible. For example, changing a posts published date will change the URL.
While we can’t control how other people will link to our site, we can control how we link to our internal sites.
By default, with permalinks enabled, when visiting WordPress with a shortlink, WordPress will redirect you to the permalink URL.
How It Works
Shortlinks hooks into the WordPress filter get_shortlink to enable shortlinks for all WordPress types.
You can use Shortlinks in your own theme or plugin.
To return the shortlink for a post, page, or custom post type, where $id represents the ID:
To return the shortlink for a category, where $id represents the category id:
To return the shortlinks for custom taxonomy, where $id represents the term id, and $taxonomy represents the custom taxonomy:
Why I Created It
WordPress supports shortlinks by default, but only allows the user to get the shortlink for a post. Finding it unacceptable, I created a plugin to get shortlinks for all content types.
