昊天SEO

使用python-wordpress-xmlrpc操作wordpress

用到的库python-wordpress-xmlrpc

url :https://github.com/maxcutler/python-wordpress-xmlrpc

新建tag或者category:

#!/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))

发表博文:

#!/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))

新建带有父category/tag的子category/tag

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))

本文地址官网    新乡网站建设,seo

本文网址:http://www.168seo.cn/jianzhan/wordpress/1970.html
分享到:更多 ()
a