KeiStory

WordPress API - Post 항목 가져오기

 

기본 : 'WordPressPCL' Nuget  패키지 설치

코드 내용

using WordPressPCL;
using WordPressPCL.Models;

namespace WordPressPCLTest
{
    public partial class WordPressForm : Form
    {
        public WordPressForm()
        {
            InitializeComponent();
        }

        private async void getPostButton_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            WordPressClient client = new WordPressClient("https://wordpress주소.kr/wp-json/");

            IEnumerable<Post> postEnumerable = await client.Posts.GetAllAsync();

            int i = 1;

            foreach (Post post in postEnumerable.Reverse())
            {
                string title = post.Title.Rendered.Trim();

                this.textBox1.Text += $"[{i.ToString("000")}] {title + Environment.NewLine}";

                i++;
            }

            this.Cursor = Cursors.Default;
        }
    }
}

 

결과

 

반응형

공유하기

facebook twitter kakaoTalk kakaostory naver band