2012-10-15 22 views
20

Tôi đang tạo một tính năng tạo bài đăng tự động trong wordpress. Ngay bây giờ, tính năng này tạo ra bài đăng blog wordpress, nhưng tôi không thể nhập danh mục.Làm cách nào để liên kết danh mục với bài đăng wordpress?

public class Post 
    { 

     public string Title { get; set; } 

     public string Description { get; set; } 

     public string PostType { get; set; } 

     public DateTime DateCreated { get; set; } 

     public DateTime DateCreatedGmt { get; set; } 

     public List<string> Categories { get; set; } 

     public List<string> MtKeywords { get; set; } 

     public string MtExcerpt { get; set; } 

     public string MtTextMore { get; set; } 

     public string MtAllowComments { get; set; } 

     public string MtAllowPings { get; set; } 

     public string WpSlug { get; set; } 

     public string WpPassord { get; set; } 

     public string WpAuthorId { get; set; } 

     public string WpAuthorDisplayName { get; set; } 

     public string PostStatus { get; set; } 

     public string WpPostFormat { get; set; } 

     public bool Sticky { get; set; } 

     public List<CustomFields> CustomFields; 

     public Enclosure Enclosure; 
    } 

tôi đã cố gắng để có được hạng nhất và vượt qua chỉ có tên loại để tránh các lỗi:

 var wordpress = XmlRpcProxyGen.Create<IWordpress>(); 

     Category[] categories= wordpress.getCategories(0, username, password); 

Phương pháp xây dựng các hạng mục bài nhận như tham số. Phương thức này thuộc về lớp Post. Danh mục được chèn vào bài đăng theo cách này:

 Categories.Add(category.categoryName); 

Có ai giúp tôi không? Tôi đã nhìn thấy rất nhiều lần mã này mà tôi không thể nhìn thấy nơi tôi đang đi sai: (.

Các thuộc tính của bài viết thu được trong tài liệu: http://codex.wordpress.org/XML-RPC_MetaWeblog_API#metaWeblog.newPost. Tôi đang sử dụng CookComputing.XmlRpc - http://xml-rpc.net/ - phiên bản 2.5 . .0

tôi nhận ra sau khi tôi đăng các câu hỏi là làm thế nào sai được xử lý loại

Để đặt bưu điện, chúng ta tạo ra:

class MetaWeblogClient : XmlRpcClientProtocol 
{ 

    [XmlRpcMissingMapping(MappingAction.Ignore)] 

    public struct Post 
    { 
     public DateTime dateCreated; 
     public string description; 
     public string title; 
     public string[] categories; 
     public string permalink; 
     public string postid; 
     public string userid; 
     public string wp_slug; 

    } 

Và khởi tạo các thuộc tính trong:

public void newPost(string userid, string password, string description, string title) 
    { 
     this.Url = "http://#########.wordpress.com/xmlrpc.php"; 

     Post post = new Post(); 

     post.categories = new string[1]; 
     post.categories[0] = "Category Name"; 
     post.dateCreated = DateTime.Now; 
     post.userid = userid; 
     post.description = description; 
     post.title = title; 

     newPost("0", userid, password, post, true); 

    } 

    [XmlRpcMethod("metaWeblog.newPost")] 

    public string newPost(string blogid, string authorId, string password, MetaWeblogClient.Post string description, bool publish) 
    { 
     //return string postid 
     return returnPostId = (string)this.Invoke("newPost", new Object[] { blogid, authorId, password, description, publish }); 

    } 

Lỗi của tôi không đề cập đến việc khởi tạo danh mục mảng. Cấu trúc ở trên không chính xác và tôi sẽ xóa nó khỏi mã của tôi.

Cảm ơn sự quan tâm của bạn.

+2

Các bạn đã thử nó với một mảng chuỗi ('string [] categories') thay vì một danh sách (' Danh sách <..> ')? – vstm

+0

Tôi nhận ra sau khi tôi đăng câu hỏi là cách xử lý sai danh mục. Tôi sẽ đăng bài như thế nào tôi có thể giải quyết vấn đề. Tôi xấu hổ vì đã không nhìn thấy nó trước đây. Bạn đúng. Cảm ơn câu trả lời: D – jAbreu

+1

Xin chào @jAbreu - bạn có thể đăng giải pháp của mình lên sự cố và đánh dấu giải pháp đó là câu trả lời không? Cảm ơn! – doublesharp

Trả lời

Các vấn đề liên quan