1 回答
TA貢獻(xiàn)2012條經(jīng)驗(yàn) 獲得超12個(gè)贊
我遇到了同樣的問(wèn)題,并且文檔根本不存在。
通過(guò)幾次試驗(yàn)和錯(cuò)誤,我發(fā)現(xiàn) WordPress 很可能不喜歡名稱(chēng)中的任何特殊字符。
就我而言,替換community-posts為communitypostshelp。
這是我們現(xiàn)在正在研究的非常粗略(但有效)的概念證明:
class PeepSo3_Sitemap_Provider extends WP_Sitemaps_Provider {
private $limit = 10; // @TODO CONFIGURABLE
public function __construct() {
$this->name = 'communityposts';
$this->object_type = 'communityposts';
}
private function sql($page_num) {
$sql =""; // your queries here;
return $wpdb->get_results($sql);
}
// retrieve a page of results
public function get_url_list( $page_num, $object_subtype = '' ) {
$url_list = [];
$posts = $this->sql($page_num);
foreach($posts as $post) {
$url_list[] = ['loc' => $post->url; // depends on your item structure
}
return $url_list;
}
// estimate how many pages are available
public function get_max_num_pages( $object_subtype = '' ) {
$posts = $this->sql(-1);
return ceil($posts[0]->count_posts/$this->limit);
}
}
// Register XML Sitemap Provider
add_filter('init', function() {
$provider = new PeepSo3_Sitemap_Provider();
wp_register_sitemap_provider( 'communityposts', $provider );
});
- 1 回答
- 0 關(guān)注
- 190 瀏覽
添加回答
舉報(bào)
