[WordPress] 外掛分享: Sewn In XML Sitemap

首頁外掛目錄 › Sewn In XML Sitemap
WordPress 外掛 Sewn In XML Sitemap 的封面圖片
30+
安裝啟用
★★★★★
5/5 分(4 則評價)
3119 天前
最後更新
問題解決
WordPress 3.6.1+ v2.0.6 上架:2014-08-12

內容簡介

2.0.3 版本更改了默認的文章類型,從僅“post”和“page”更改為全部公開的文章類型,除了“attachment”。這是一種更清潔的方法,但可能需要進行自定義設置。下面有更多有關自定義設置的信息。

本網站不會通知新的支持主題,因此請通過我們的表格發送聯繫以通知新的主題,以獲得更快的回應。

簡單的方式在保存頁面或文章時自動生成 XML 網站地圖。非常簡單,沒有你不會使用的冗餘或額外功能。有兩種主要的自定義設置可供選擇。

選擇要添加的文章類型(默認為文章和頁面)
在所有包含的文章類型中添加一個元框以防止將單個文章添加到網站地圖中

它也可以與我們的Sewn In Simple SEO插件很好地配合使用。當兩者都安裝時,它們會集成在一起。

控制添加文章類型
/**
* 完全替換 XML 網站地圖中的文章類型
*
* 這將完全替換默認設置。返回: array('news','event')
*
* 結果是刪除“post”和“page”文章類型,並添加“news”和“event”文章類型
*
* @param array $post_types 要添加到 XML 網站地圖的文章類型列表
* @return array $post_types 修改過的文章類型列表
*/
add_filter( 'sewn/seo/post_types', 'custom_seo_post_types' );
function custom_seo_post_types( $post_types )
{
$post_types = array('news','event');
return $post_types;
}

從網站地圖中刪除特定文章

在包含在網站地圖中的每個文章類型中添加了一個勾選框。勾選框將從網站地圖中刪除該特定項目。

此勾選框還將從 wp_list_pages 中刪除文章,您可以使用以下過濾器關閉它:

add_filter( 'sewn/sitemap/wp_list_pages', '__return_false' );

/**
* 這個過濾器是在 2.0.3 中新增的
*
* 程式設計方式刪除特定文章。這個功能可以放到 functions.php 或插件中。
*
* 這個例子會刪除所有具有“test”設置的文章。
*/
add_filter( 'sewn/sitemap/post', 'custom_remove_test_posts', 10, 2 );
function custom_remove_test_posts( $value, $post )
{
$status = get_metadata( 'post', $post->ID, 'test', true );
if ( $status ) {
$value = false;
}
return $value;
}

更改文章類型的頻率,也可以通過檢查 $post-ID 或 $post->post_name 以單獨使用
/**
* 更改 XML 中的網站地圖頻率,默認為“每月”
*
* 選項:always、hourly、daily、weekly、monthly、yearly、never
*/
add_filter( 'sewn/sitemap/frequency', 'custom_sitemap_frequency', 10, 2 );
function custom_sitemap_frequency( $frequency, $post )
{
if ( 'news' == get_post_type($post) ) {
$frequency = 'daily';
}
return $frequency;
}

相容性

可以與Sewn In Simple SEO插件一起使用。當安裝時,XML 網站地圖勾選框與 SEO 欄位集成,此插件將使用 SEO 文章類型。目標是保持非常簡單和集成。

外掛標籤

開發者團隊

⬇ 下載最新版 (v2.0.6) 或搜尋安裝

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

原文外掛簡介

2.0.3 changed default post types used from only ‘post’ and ‘page’ to ALL public post types except “attachment”. This is a cleaner approach, but may require customization. There is more info on customization below.
This site doesn’t notify of new support threads, so send a contact through our form to notify of a new thread for a quicker response.
Simple way to automatically generate XML Sitemaps when a page or post is saved. Very simple, no cruft or extra features you won’t use. There are two main customizations available.

Choose which post types are added (posts and pages by default)
Adds a meta box to all included post types to remove single posts from being added to the sitemap

It also works well with our Sewn In Simple SEO plugin. When both are installed, they integrate together.
Control what post types are added
/**
* Completely replace the post types in the XML sitemap
*
* This will replace the default completely. Returns: array('news','event')
*
* The result is to remove 'post' and 'page' post types and to add 'news' and
* 'event' post types
*
* @param array $post_types List of post types to be added to the XML Sitemap
* @return array $post_types Modified list of post types
*/
add_filter( 'sewn/seo/post_types', 'custom_seo_post_types' );
function custom_seo_post_types( $post_types )
{
$post_types = array('news','event');
return $post_types;
}

Remove a specific post from the sitemap
A checkbox is added to each post type that is included in the sitemap. Checking it will remove that specific item from the sitemap.
This checkbox also removes posts from wp_list_pages, you can turn that off using this filter:
add_filter( 'sewn/sitemap/wp_list_pages', '__return_false' );

/**
* This filter arrived in 2.0.3
*
* Remove specific posts programatically. This could go into functions.php or a plugin.
*
* This example removes all posts that have post meta field of "test" set.
*/
add_filter( 'sewn/sitemap/post', 'custom_remove_test_posts', 10, 2 );
function custom_remove_test_posts( $value, $post )
{
$status = get_metadata( 'post', $post->ID, 'test', true );
if ( $status ) {
$value = false;
}
return $value;
}

Change frequency for a post type, could also be used an a single post basis by checking the the $post-ID or $post->post_name
/**
* Change sitemap frequency in XML, default is "monthly"
*
* options: always, hourly, daily, weekly, monthly, yearly, never
*/
add_filter( 'sewn/sitemap/frequency', 'custom_sitemap_frequency', 10, 2 );
function custom_sitemap_frequency( $frequency, $post )
{
if ( 'news' == get_post_type($post) ) {
$frequency = 'daily';
}
return $frequency;
}

Compatibility
Works with the Sewn In Simple SEO plugin. When installed, the XML sitemap checkbox integrates with the SEO fields and this plugin will use the SEO post types. The goal is to keep things very simple and integrated.

延伸相關外掛

文章
Filter
Apply Filters
Mastodon