Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
REST API な WordPress テーマについて考える。
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Toro_Unit (Hiroshi Urabe)
September 03, 2017
Technology
1.2k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
REST API な WordPress テーマについて考える。
Toro_Unit (Hiroshi Urabe)
September 03, 2017
More Decks by Toro_Unit (Hiroshi Urabe)
See All by Toro_Unit (Hiroshi Urabe)
WordPress のサイト制作について改めて考える Toro_Unit / 2026.07.25 @ Shinshu WordPress Meetup
torounit
0
180
ブロックテーマ、WordPress でウェブサイトをつくるということ / 2026.02.07 Gifu WordPress Meetup
torounit
0
780
ブロックテーマでサイトをリニューアルした話 / 2026-01-31 Kansai WordPress Meetup
torounit
0
620
ブロックテーマとこれからの WordPress サイト制作 / nishinomiya.dev@2025-12-21
torounit
1
300
ブロックテーマとこれからの WordPress サイト制作 / Toyama WordPress Meetup Vol.81
torounit
0
820
ブロックテーマ時代における、テーマの CSS について考える Toro_Unit / 2025.09.13 @ Shinshu WordPress Meetup
torounit
0
880
ブロックテーマでサイトリニューアルした話 / Toro_Unit / 2025.04.12 @ Shinshu WordPress Meetup
torounit
1
370
Cloudflare Meetup Nagano Vol.3
torounit
1
190
僕が考える 「HTML サイトを WordPress にする」話 / 2023-11-05 Kansai WordPress Meetup
torounit
9
8.9k
Other Decks in Technology
See All in Technology
AI-DLC実践録_フルサイクル開発への挑戦
miyuc
0
390
Model Studio CLI × Token Plan
maigo999
0
210
Oracle MCP Servers Explained
thatjeffsmith
0
440
サイボウズ 開発本部採用ピッチ / Cybozu Engineer Recruit
cybozuinsideout
PRO
12
85k
安全性・開発速度・ユーザー体験の あいだで考える 事業会社のプロダクトセキュリティ
mixi_engineers
PRO
0
100
Adding Right-to-Left support to your web application with CSS logical properties — Lessons from Redmine
vividtone
0
180
LLM Internals: 언어 모델의 계보와 알고리즘 진화 (2023~2026)
inureyes
PRO
1
890
国家プロジェクトを支える「さくらONE」 大規模LLM開発におけるGPU障害を乗り越えるクラスター運用戦略
gpuunite_official
0
270
カーネルまで探検して理解するふたつの自動計装
sumiyae
0
260
NANDでも描画したい!
nichica906
3
630
AIのためのEthernet技術動向 (SerDes)
markunet
1
310
VLMで2.3万枚のPyCon JP写真を検索!
terapyon
1
420
Featured
See All Featured
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Paper Plane
katiecoart
PRO
2
53k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.8k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
620
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.1k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
Navigating Weather and Climate Data
rabernat
0
490
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Test your architecture with Archunit
thirion
2
2.4k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
420
Everyday Curiosity
cassininazir
0
290
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
3
480
Transcript
REST API ͳ WordPress ςʔϚʹͭ ͍ͯߟ͑Δɻ Toro_Unit @2017.09.03/RESTࡇΓ 1
Toro_Unit ෦ ߛ (͏Β ͻΖ͠) ϑϦʔϥϯε Frontend Engineer / Web
Designer Github: @torounit Twitter: @Toro_Unit Facebook: fb.me/torounit Blog: https://torounit.com 2
Plugin and Theme Developer. • Custom Post Type Permalinks •
Vanilla • and more... 3
Contribution • WordBench ϞσϨʔλʔ • WordCamp Kyoto 2017 ࣮ߦҕһ
• VCCW Team • etc... 4
ݝদຊࢢ͔Β͓ૹΓ͠· ͢ɻ1 • ϫΠϯ͓͍͍͠Αɻ • ͦΖͦΖڶഴ͓͍͍͠Αɻ 1 https://commons.wikimedia.org/wiki/File: 130608_Matsumoto_Castle_Matsumoto_Nagano_pref_Japan02bs4.jpg Author:
663highland. License: CC BY 2.5 5
ຊҰඒຯ͍͍͔͕͋͢͠Δͱ͔ແ͍ͱ͔ɻ 6
ຊͷऴిҊ 7
REST API Λ׆༻ͯ͠ɺWEBαΠτΛ ͭ͘Δɻ 8
9
10
11
طʹ࣮༻Խ͞Ε͍ͯΔέʔε͚ͬ͜ ͏͋Δɻ 12
13
• ಠཱͨ͠ΞϓϦέʔγϣϯ͕ɺWordPressΛόοΫΤϯυͱ ͯ͠ѻ͏ɻ • WordPressͷׂ = σʔλཧٴͼɺJSONͰͷσʔλग़ ྗɻ 14
WordPressͷςʔϚͰ࣮ݱͰ͖ͳ͍ ͩΖ͏͔ʁ 15
• WordPressͷςʔϚͰϦονͳϢʔβʔମݧ • ϦονͳϖʔδભҠɻ • ϦΞϧλΠϜͳσʔλߋ৽ɻ • REST API Λ׆༻͢Δ͜ͱͰɺPWAͷରԠεϜʔζʹɻ
• ΦϑϥΠϯϑΝʔετͷ࣮ݱɻ • طଘͷWordPress͔ΒͷҠߦɻ • ϓϨϏϡʔͰαΠτͷݟͨΛ֬ೝɻ 16
17
͍͠ͱݴΘΕ͍ͯΔɻ ςʔϚͷ߹ϧʔςΟϯάͳͲɺWordPressͰߦ͍ͬͯΔ͜ͱ Λ࡞Γ͢ඞཁ͕͋ΓɺͪΐͬͱτϦοΩʔͱίϝϯτɻ ΠϕϯτϨϙʔτɿWordPress Meetup Tokyo #34 - AMA Session
with Joe Hoyle and Bryce Adams - Capital P 18
Wallace Wallace WordPress Theme • A next-generation* WordPress theme built
with the Rest API and Angular 19
ࣗͬͯΈͨɻ 20
torounit/vuepress 21
DEMO 22
23
Ͱ͖ͯΔ! 24
ͦΜͳʹ͘ͳ͍ɻ ՝͕ࢁੵΈɻ 25
URLͷύʔεʹ͍ͭͯ 26
• WEBαΠτඞͣ͠TOPϖʔδ͔ΒΞΫηε͞ΕΔΘ͚Ͱ ͳ͍ɻ • URL͔Βදࣔ͢Δίϯςϯπɺঢ়ଶʢهࣄϖʔδʁΧςΰϦ ʔʁʣΛݕࡧ͢Δඞཁ͕͋Δɻ • ͦͯ͠ύʔϚϦϯΫཧը໘͔Βࣗ༝ʹઃఆՄೳ!!! 27
Vue Router Λ͏έʔεɻ URLͷύεϕʔεɻ 28
Category, Tag, Date λΫιϊϛʔɺURLͷϕʔεɺ/category/, /tag/ Λ WordPress͔Β͢ɻ ϕʔεͷURLɺURLߏΛ WP_Rewrite::get_date_permastruct ͔ΒऔಘɻJSʹ͠ਖ਼
نදݱʹมɻ 29
WordPress͔ΒJSʹΛ͢ wp_localize_script Λ͑ग़དྷΔɻʢຊདྷͷ༻๏ͱͣ ΕΔؾ͢Δ͚Ͳʣ wp_localize_script( 'vuepress-script', 'WPSettings', [ 'root' =>
esc_url_raw( rest_url() ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'date_permastruct' => $wp_rewrite->get_date_permastruct(), 'page_on_front' => get_option('page_on_front'), 'page_for_posts' => get_option('page_for_posts'), 'category_base' => get_option('category_base') ? get_option('category_base') : 'category', 'tag_base' => get_option('tag_base') ? get_option('tag_base') : 'tag' ] ); 30
ߘܥ 31
http://example.com/sample-page/ (ݻఆϖʔδ) http://example.com/hello-world/ (ߘ) ΛͲ͏ͬͯ۠ผ͢Δʁ 32
ࠓճɻ 1. /wp-json/vuepress/v1/post/<URL> ͱ͍͏APIΛ࡞ɻ 2. category, tag, date, ͷ݅ʹϚον͠ͳ͔ͬͨશͯͷURL Λ͜ͷAPIʹ͛Δɻ
3. url_to_postid ͰURL͔Β postID Λݕࡧ 4. get_post ͰߘσʔλΛऔಘ͠ฦ٫ɻ 33
add_action( 'rest_api_init', function () { register_rest_route( 'vuepress/v1', '/post/(?P<url>.*)', array( 'methods'
=> 'GET', 'callback' => function ( $request ) { $post_id = url_to_postid( $request['url'] ); if ( ! $post_id ) { return []; } $post = get_post( $post_id ); $post_type = get_post_type_object( $post->post_type ); $request['id'] = $post_id; $response = new WP_REST_Posts_Controller( $post->post_type ); return $response->get_item( $request ); } ) ); } ); 34
ͳ͔ͳ͔ແཧཧͳ࣮ɻ 35
͔͜͠͠ΕͰΓͳ͍ɻ 36
σϑΥϧτͷ WordPressʹࡌ͞ ΕΔRewrite Rule 90ݸ 37
"Clean URL"Ͱͳ͍URLͷରԠ • /?s=hoge /search/hoge ͱՁͰ͋Δ͕ϦμΠϨΫτ͞Εͳ͍!!! • /?cat=1 ϦμΠϨΫτ͞ΕΔ͕ɺ/?cat=1&cat=2 •
/?p=123ͷɺ"Clean URL"Λ༻͍ͯ͠ͳ͍έʔεɻ • ৽نߘͷϓϨϏϡʔɺ/?p=123&preview=true ܗࣜʹͳΔɻ • URL ͔Β /caregory/ Λফ͍ͨ͠ͱ͔͍͏ෆಧ͖ऀଟ͍ 38
Ͳ͏͠Α͏ʁ • WP_Rewirte / WPΫϥεͷ Α͏ͳϞϊΛJavaScriptͰ࠶࣮ ͢Δʁ • ͦͦͬͱΑ͍Ξϓϩʔν͕͋Δʁ 39
Let's think together 40
Thanks! Github: @torounit Twitter: @Toro_Unit Facebook: fb.me/torounit Blog: https://torounit.com 41