2015-04-20 184 views
1

我試圖用拇指圖像添加新帖子,但我仍然無法取得成功。添加張貼圖像縮略圖到Wordpress博客與JoeBlogs/C#

public static int addContent(int postType, string title, string body, string post_thumbnail, string[] categories, string[] tags, DateTime dateCreated) 
{ 
    Post post = setPost(postType, title, body, post_thumbnail, categories, tags, dateCreated); 
    using (var wrapper = getWordPressWrapper()) 
    { 
    return wrapper.NewPost(post, true); 
    } 
} 

得到setPost方法,

public static Post setPost(int postType, string title, string body, string post_thumbnail, string[] categories, string[] tags, DateTime dateCreated) 
{ 
    string type = postType == 1 ? "post" : "page"; 
    var customFields = new CustomField[] { 
    new CustomField() { 
     // Don't pass in ID. It's auto assigned for new custom fields. 
     // ID = "name", 
     Key = "post_thumbnail", 
     Value = post_thumbnail 
    } 
    //, 
    //  new CustomField() { 
    // // Don't pass in ID. It's auto assigned for new custom fields. 
    // // ID = "name", 
    // Key = "post-thumbnail", 
    // Value = post_thumbnail 
    //} , 
    //  new CustomField() { 
    // // Don't pass in ID. It's auto assigned for new custom fields. 
    // // ID = "name", 
    // Key = "post-thumbnails", 
    // Value = post_thumbnail 
    //} , 
    //  new CustomField() { 
    // // Don't pass in ID. It's auto assigned for new custom fields. 
    // // ID = "name", 
    // Key = "thumbnail", 
    // Value = post_thumbnail 
    //} 
    }; 
    return new Post 
    { 
    PostType = type, 
    Title = title, 
    Body = body, 
    Categories = categories, 
    Tags = tags, 
    DateCreated = dateCreated, 
    CustomFields = customFields 
    }; 
} 

當你看到它的評論。我嘗試了一切發佈拇指圖像。

我試過post_thumbnail,後縮略圖,後縮略圖,縮略圖鍵,但沒有發生。

我該怎麼做?

回答

0

假設縮略圖已經上傳了,你知道它的介質ID,

Key = "_thumbnail_id", 
Value = id_of_uploaded_thumbnail 

應該工作。

+0

我已經試過了你的鑰匙和所有其他可能。沒有改變。 post_thumbnail = 「603」; – tayfun

+0

@tayfun只是爲了檢查,如果你去'domain.com?p = 603',它是否顯示媒體附件? – enigma

+0

是的,我現在沒有。其重定向到一個圖像xxx.com/?p=603 – tayfun

相關問題