wp-net / WordPressPCL

This is a portable library for consuimg the WordPress REST-API in (almost) any C# application
MIT License
338 stars 129 forks source link

how to use post with media #171

Closed gandol2 closed 5 years ago

gandol2 commented 5 years ago

I want to insert the media into the post. With HTML tags ..

Please give us an example.

polushinmk commented 5 years ago

How to upload Media How to create Tag

after this you can create Post

var post = new Post() {
    Tags = new int[] { tagId }, //id of created tag
    //path to uploaded image
    Content = new Content($"content text with html tags. you can insert image like this <img src =\"{IMAGE_PATH}\" />"),
   //any other post properties
}
//create post
await client.Posts.Create(post);
gandol2 commented 5 years ago
  1. Upload the image.
  2. Get the path to the image.
  3. Enter the content and image path in HTML.

Is this the same sequence?

polushinmk commented 5 years ago

Same. Create Media method returns you created media object. You can try it all on your site

gandol2 commented 5 years ago

thank you. i have another question.

how to get image size (with and height)?

when i post content including image, i want to include size information.

polushinmk commented 5 years ago

created Media object has property MediaDetails of type MediaDetails which has properties Width, Height (and all kind of Sizes). you can find it in out codebase MediaItem MediaDetails

gandol2 commented 5 years ago

i see. thank you :)