1 回答
TA贡献2012条经验 获得超12个赞
我遇到了同样的问题,并且文档根本不存在。
通过几次试验和错误,我发现 WordPress 很可能不喜欢名称中的任何特殊字符。
就我而言,替换community-posts为communitypostshelp。
这是我们现在正在研究的非常粗略(但有效)的概念证明:
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 关注
- 96 浏览
添加回答
举报