URL segments and the page reference field

Posted 16th Dec 2017

#api #bootstrap4 #completeguide #fields #selector #urlsegments

Create a new page under 'Cats' which will hold the data for a single cat entry.

Creating a new cat entry page
Creating a new cat entry page Zoom

If you look at your new page, you'll see 'Type of cat' with a 'Create New' button. The way we set this up, you can now create pages on the fly which will be listed under '/type/'. Awesome or what! So let's add a new page.

Using the create new button
Using the create new button Zoom

Now go and check out your page tree, you'll see that you just created a new page.

Showing the newly created child page under /type/
Showing the newly created child page under /type/ Zoom

Now if you edit the actual 'Burmese' page you'll see that if has a path of '/type/burmese/'. Now, this is where you could decide whether to use URL segments or not.

The cat type attribute page
The cat type attribute page Zoom

If you (a) had a template file called 'cat-attribute.php' and (b) wanted a page at 'site.com/type/burmese' then you don't need URL segments. The page tree structure naturally allows for these paths and you could put code in that file that would be run at this URL. Right now, this file does not exist so this URL would give you a 404 not found until you created the file. Notice that when you hover over 'Burmese' in the page tree, the 'View' button is not present. This is because there is no corresponding file.

However, if you wanted to list cats of type 'Burmese' at '/site.com/cats/burmese/' then you would need URL segments as this is not a natural path in the page tree. This is what we are going to do.

Makes sense? Hopefully, it should become clearer as we go on.

I created a bunch of pages with images of cats purely for educational purposes, not purely for fun, honestly.

Page tree showing new cat pages and types
Page tree showing new cat pages and types Zoom

So in the next part of the guide, we'll render this stuff out and use URL segments to show different things at different URLs.

Feedback & support

I hope you enjoyed this tutorial. You can support pwtuts by following on @pwtuts. You can also donate at paypal.me/swcarrey to help support the site which would be awesome!

Related tutorials / See all

Suggest a tutorial

Please note: I do not store any of this information, it's simply used to send me an email. Your email address is required so I can get clarification on your request if needed.