用到的庫python-wordpress-xmlrpcphp
url :python
https://github.com/maxcutler/python-wordpress-xmlrpcgit
新建tag或者category:github
#!/usr/bin/env python #-*- coding: utf-8 -*- from wordpress_xmlrpc import Client, WordPressPost, WordPressTerm from wordpress_xmlrpc.methods.posts import GetPosts, NewPost from wordpress_xmlrpc.methods.users import GetUserInfo from wordpress_xmlrpc.methods import taxonomies import csv wp = Client('http://127.0.0.1/xmlrpc.php', 'root', '123456') tag = WordPressTerm() tag.taxonomy = 'category'#這裏爲category的話插入的是category,爲post_tag的話插入的是tag tag.name = 'My New Tag' tag.id = wp.call(taxonomies.NewTerm(tag))
發表博文:wordpress
#!/usr/bin/env python #-*- coding: utf-8 -*- from wordpress_xmlrpc import Client, WordPressPost, WordPressTerm from wordpress_xmlrpc.methods.posts import GetPosts, NewPost from wordpress_xmlrpc.methods.users import GetUserInfo from wordpress_xmlrpc.methods import taxonomies import csv wp = Client('http://127.0.0.1/xmlrpc.php', 'root', '123456') """ 發表博文 """ post = WordPressPost() post.title = 'My new title' post.content = 'This is the body of my new post.' post.post_status = 'publish' post.terms_names = { 'post_tag': ['test', 'firstpost'], 'category': ['Introductions', 'Tests'] } wp.call(NewPost(post))
搜索tag/category:post
tags = client.call(taxonomies.GetTerms('category', {'search':'子目錄'}))# 子目錄 是 category/tag的name
新建帶有父category/tag的子category/tagurl
parent_cat = client.call(taxonomies.GetTerm('category', 3)) child_cat = WordPressTerm() child_cat.taxonomy = 'category'#這裏爲category的話插入的是category,爲post_tag的話插入的是tag child_cat.parent = parent_cat.id child_cat.name = 'My Child Category' child_cat.id = client.call(taxonomies.NewTerm(child_cat))