2012-10-15 15 views
20

Tworzę funkcję, która tworzy automatyczne posty w Wordpress. Teraz ta funkcja tworzy blog na blogu, ale nie mogę wejść do kategorii.Jak powiązać kategorię z postpressem?

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; 
    } 

Próbowałem dostać się do klasy pierwszej i przechodzić tylko nazwę kategorii, aby uniknąć błędów:

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

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

metodę, która buduje kategoria postu otrzymuje jako parametr. Ta metoda należy do klasy Post. Kategoria jest umieszczana w poście w ten sposób:

 Categories.Add(category.categoryName); 

Czy ktoś może mi pomóc? Widziałem tak wiele razy ten kod, że nie widzę gdzie idę źle: (.

Atrybuty Post zostały uzyskane w dokumentacji: http://codex.wordpress.org/XML-RPC_MetaWeblog_API#metaWeblog.newPost. Używam CookComputing.XmlRpc - http://xml-rpc.net/ - wersja 2.5 . 0,0

zdałem sobie sprawę po Zamieściłem pytanie było jak źle obsługiwał kategorię

Aby umieścić posta, tworzymy:

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; 

    } 

i zainicjować atrybuty:

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

    } 

Mój błąd polegał nie na inicjowaniu kategorii tablic. Powyższa struktura jest nieprawidłowa i usunę ją z mojego kodu.

Dziękuję za uwagę.

+2

Czy już próbował go z tablicy ciągów ('string [] categories') zamiast listy (' List <..> ')? – vstm

+0

Uświadomiłem sobie, że po tym, jak napisałem, pytanie brzmiało, jak niewłaściwa była obsługa kategorii. Opublikuję, jak mogę rozwiązać problem. Wstydzę się, że wcześniej tego nie widziałem. Masz rację. Dziękujemy za odpowiedź: D – jAbreu

+1

Witaj @jAbreu - czy mógłbyś zamieścić swoje rozwiązanie problemu i oznaczyć je jako odpowiedź? Dzięki! – doublesharp

Odpowiedz