wordpress_xmlrpc模块批量自动发布文章到wordpress-WordPress开发教程
使用python的,模块的使用方法请看https://python-wordpress-xmlrpc.readthedocs.io/en/latest/安装easy_install python-wordpress-xmlrpc 或者 pip install python-wordpres
使用python的,模块的使用方法请看https://python-wordpress-xmlrpc.readthedocs.io/en/latest/
安装
easy_install python-wordpress-xmlrpc 或者 pip install python-wordpress-xmlrpc
使用
#带有自定义栏目字段的发布文章代码 #coding:utf-8 from wordpress_xmlrpc import Client, WordPressPost from wordpress_xmlrpc.methods.posts import GetPosts, NewPost from wordpress_xmlrpc.methods.users import GetUserInfo from wordpress_xmlrpc.methods import posts from wordpress_xmlrpc.methods import taxonomies from wordpress_xmlrpc import WordPressTerm from wordpress_xmlrpc.compat import xmlrpc_client from wordpress_xmlrpc.methods import media, posts import sys reload(sys) sys.setdefaultencoding('utf-8') wp = Client('http://您的域名/xmlrpc.php', '后台账号', '后台密码') post = WordPressPost() post.title = '文章标题' post.content = '文章内容' post.post_status = 'publish' #文章状态,不写默认是草稿,private表示私密的,draft表示草稿,publish表示发布 post.terms_names = { 'post_tag': ['test', 'firstpost'], #文章所属标签,没有则自动创建 'category': ['Introductions', 'Tests'] #文章所属分类,没有则自动创建 } post.custom_fields = [] #自定义字段列表 post.custom_fields.append({ #添加一个自定义字段 'key': 'price', 'value': 3 }) post.custom_fields.append({ #添加第二个自定义字段 'key': 'ok', 'value': '天涯海角' }) post.id = wp.call(posts.NewPost(post))
#带有特色图像缩略图的发布文章 #coding:utf-8 from wordpress_xmlrpc import Client, WordPressPost from wordpress_xmlrpc.methods.posts import GetPosts, NewPost from wordpress_xmlrpc.methods.users import GetUserInfo from wordpress_xmlrpc.methods import posts from wordpress_xmlrpc.methods import taxonomies from wordpress_xmlrpc import WordPressTerm from wordpress_xmlrpc.compat import xmlrpc_client from wordpress_xmlrpc.methods import media, posts import sys reload(sys) sys.setdefaultencoding('utf-8') wp = Client('http://您的域名/xmlrpc.php', '后台账号', '后台密码') filename = './my.jpg' #上传的图片文件路径 # prepare metadata data = { 'name': 'picture.jpg', 'type': 'image/jpeg', # mimetype } # read the binary file and let the XMLRPC library encode it into base64 with open(filename, 'rb') as img: data['bits'] = xmlrpc_client.Binary(img.read()) response = wp.call(media.UploadFile(data)) # response == { # 'id': 6, # 'file': 'picture.jpg' # 'url': 'http://www.example.com/wp-content/uploads/2012/04/16/picture.jpg', # 'type': 'image/jpeg', # } attachment_id = response['id'] post = WordPressPost() post.title = '文章标题' post.content = '文章正文' post.post_status = 'publish' #文章状态,不写默认是草稿,private表示私密的,draft表示草稿,publish表示发布 post.terms_names = { 'post_tag': ['test', 'firstpost'], #文章所属标签,没有则自动创建 'category': ['Introductions', 'Tests'] #文章所属分类,没有则自动创建 } post.thumbnail = attachment_id #缩略图的id post.id = wp.call(posts.NewPost(post))
#除了可以发布文章,这个模块也可以单独创建新的分类和标签 #coding:utf-8 from wordpress_xmlrpc import Client, WordPressPost from wordpress_xmlrpc import WordPressTerm from wordpress_xmlrpc.methods import taxonomies import sys reload(sys) sys.setdefaultencoding('utf-8') wp = Client('http://您的域名/xmlrpc.php', '后台账号', '后台密码') #新建标签 tag = WordPressTerm() tag.taxonomy = 'post_tag' tag.name = 'My New Tag12'#标签名称 tag.slug = 'bieming12'#标签别名,可以忽略 tag.id = wp.call(taxonomies.NewTerm(tag))#返回的id #新建分类 cat = WordPressTerm() cat.taxonomy = 'category' cat.name = 'cat1'#分类名称 cat.slug = 'bieming2'#分类别名,可以忽略 cat.id = wp.call(taxonomies.NewTerm(cat))#新建分类返回的id #新建子分类 parent_cat = client.call(taxonomies.GetTerm('category', 20))#20是父分类的id child_cat = WordPressTerm() child_cat.taxonomy = 'category' child_cat.parent = parent_cat.id child_cat.name = 'My Child Category'#分类名称 child_cat.slug = 'beidongdui'#分类别名,可以忽略 child_cat.id = wp.call(taxonomies.NewTerm(child_cat))#新建分类返回的id
原创文章,作者:DavidWu,如若转载,请注明出处:https://www.davidwu.net/archives/121686

服务项目 | 服务内容 | 收费标准(元) |
---|---|---|
开发定制 | WordPress主题/插件开发定制 | (以最终需求为准) |
主题/插件汉化 | 汉化团队WordPress主题/插件,翻译率95% | (以标的主题/插件的句子数量为准) |
服务器环境配置 | 基于您现有服务器,搭建配置网站运行环境,结合我们多年来实战经验,可完美支持WordPress等PHP程序运行,并配置伪静态规则、优化目录权限等问题。服务器我们强烈推荐使用Linux系统。 | 100元/次 |
网站托管 | 若贵站目前尚无技术人员,无法完成服务器环境配置,可选择我们的网站托管服务,直接交付正常运行的WordPress站点,并且无需担心服务器的后续维护工作,一切都由我们来帮您完成。 | 标配套餐:1000元/年/站点 高配套餐:联系客服获取 |
网站加速优化 | 从服务器后端配置优化到WordPress数据库缓存、前端页面缓存、JS和CSS压缩合并,全方位优化网站加载速度,实现秒开。(此服务仅针对(云)服务器/VPS) | 500元/次(仅站内优化200元/次) |
主题配置 | 本站所有主题均支持,可快速实现,若有任何问题可以咨询客服解决,若您希望我们提供配置服务,可选购此服务。 | 英文主题安装 60元/次 汉化主题安装 30元/次 |
HTTPS配置 | HTTPS已经不断普及,并且有着更高的安全性以及SEO上的优待。该服务收取的为服务费,SSL证书产生的费用请自行承担。 | 100元/次 |
网站搬家 | 迁移网站所有文件和数据库信息、网站相关配置的调整、以及迁移中的疑难问题故障排除。 | 标准收费:500元/次 若网站数据量大,需协商 |
网站运维 | 提供整站的运维服务,保证网站正常运行。包含:网站故障定位及排除、网站数据备份和恢复、网站攻击及木马等问题的处理等 | 标准收费:2000元/年 IP 5000以上需协商 |