The team is now working on the WordPress Interactivity API. This unblocks the same UX Frontity framework enabled but directly in WordPress Core, fully compatible with the new Site Editor.
Oh wow, that looks much simpler than anything I would have attempted. Thank you! I will try it that way.
matthewbertweb6
Wow, that solution was so easy! I was definitely expecting to have to do a lot more. Thank you for the help!
2 Likes
bjerling7
What if you would want to create it more like wp page themes? I cant see that the selected page theme is included in the state. Thought about doing the same conditional selection, but with some more reusable identifier than the page url.
If so, then WordPress in fact also uses the URL to determine which template to use. The “pretty permalink” is converted into query string parameters which WordPress uses to choose which template from the theme to use.
So the mechanism with Frontity isn’t really that much different, except that you choose the React component to use based on the “pretty permalink”, i.e. the URL you see in the browser address bar.
That said, Frontity does have some information in the state to help you choose different components. For example, the homepage will have the isHome property set to true in state.source.data, so you can check that to use a different component for your homepage from the component used for all the other pages in your theme.
When developing your site it’s worth keeping the console open and checking frontity.state.source to see what properties you’ve got available to use in the conditionals that you want to use.
bjerling9
Thanks
I meant more like what @matthewbertweb asked about. But not hardcoding a slug/url as the condition, but rather a variable that comes from WP. Like the page template for example - which is kind of made for that in basic php WP. I couldnt find that variable in the API.
I want it to be possible for the CMS user to change between layouts for specific pages.
I guess could just add an ACF setting for this, as I already have that set up. But wouldn’t it be more appropriate to use the regular page template option from the WP core?
Is there anything else necessary? I’ve created the page, imported to index and copied a regular pages template of with some minor changes, but nothing. I’m sure i’m missing something easy! Thanks for any help!
When the data.isPage condition is met the switch doesn’t try any more conditions so the CustomPage line is never evaluated.
Let me know if this fixes things for you.
james.c.yarbrough13
Brilliant Micheal! It’s working beautifully! Thank you so much for your hard work! I’m setting up a CPT with the aid of your tutorial and repo! Can’t wait to display this site i’ve been making!
2 Likes
james.c.yarbrough14
@mburridge Just a little follow up - here is the site! I used kasper’s aamodtgroup theme!
uptownrecords.eu
1 Like
mburridge15
Wow, great work @james.c.yarbrough. The site looks amazing!
Please consider submitting it for inclusion in our showcases page.