簡體   English   中英

使用 python-wordpress-xmlrpc 將圖片庫上傳到 wordpress

[英]Upload images gallery to wordpress with python-wordpress-xmlrpc

好的,我已經使用“python-wordpress-xmlrpc”包在python中創建了一個腳本,除了將多個圖像上傳到wordpress然后將它們添加到圖庫之外,我可以做任何事情。

這是我上傳單個圖像文件然后設置為特征圖像的代碼:

fileImg = urlopen('image_url')
imageName = fileImg.url.split('/')[-1]
imageType = mimetypes.guess_type(str(fileImg.url))[0]

data = {
    'name': imageName,
    'type': imageType,
}

data['bits'] = xmlrpc_client.Binary(fileImg.read())

response = client.call(media.UploadFile(data))
attachment_id = response['id']
widget.thumbnail = attachment_id

注意:我知道如何上傳多個文件,但我不明白如何在產品庫中添加這些圖像。

這種技術對我有用:

attachment_id = response['id']
alt_value = "image alt"

sql = """INSERT INTO wp_postmeta (post_id,meta_key,meta_value) VALUES (%d,'_wp_attachment_image_alt','%s');""" % (int(attachment_id ), alt_value)
mycursor.execute(sql)
mydb.commit()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM