2012-10-15 10 views
20

Sto creando una funzionalità che crea post automatizzati in wordpress. In questo momento, la funzione crea il post del blog wordpress, ma non posso inserire la categoria.Come associare una categoria a un wordpress post?

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

ho cercato di arrivare alla prima classe e passare solo il nome della categoria per evitare errori:

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

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

Il metodo che costruisce la categoria postale riceve come parametro. Questo metodo appartiene alla classe Post. La categoria è inserita nel post questo modo:

 Categories.Add(category.categoryName); 

Qualcuno mi potrebbe aiutare? Ho visto tante volte questo codice che non riesco a vedere dove sto andando male: (

Gli attributi di Post sono stati ottenuti nella documentazione: http://codex.wordpress.org/XML-RPC_MetaWeblog_API#metaWeblog.newPost sto usando CookComputing.XmlRpc - http://xml-rpc.net/ - versione 2.5.. . 0,0

ho capito dopo che ho postato la domanda era come sbagliato è comportata categoria

Per posizionare il post, creiamo:

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; 

    } 

e inizializzare gli attributi in:

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'errore non si riferiva all'inizializzazione della categoria di array. La struttura sopra non è corretta e la rimuoverò dal mio codice.

Grazie per la vostra attenzione.

+2

Avete già provato con un array di stringhe ('string [] categories') invece di una lista (' Lista <..> ')? – vstm

+0

Mi sono reso conto dopo che ho postato la domanda è stata la gestione errata della categoria. Pubblicherò come potrei risolvere il problema. Mi vergogno di non averlo visto prima. Hai ragione. Grazie per la risposta: D – jAbreu

+1

Ciao @jAbreu: potresti pubblicare la soluzione al problema e contrassegnarla come risposta? Grazie! – doublesharp

risposta

Problemi correlati