If you didn’t know already, this blog is not the only thing that we work on — we also take on clients to work on website and web-related projects for them. Recently, we worked on a website project where we had to code a custom WordPress post type into the custom theme we made for the client (yes we make those).
This custom post type (which shall henceforth be called Articles — what we named the post type) was supposed to serve a purpose similar to the default WordPress Post — it was meant to go into a blog section for the website, and the client wanted to be able to assign categories to individual articles. All of this is pretty standard fare when it comes to WordPress customisation, as you can easily figure out how to do it reading official guides and documentation from WordPress:
- Adding custom post types: developer.wordpress.org/plugins/post-types/
- Adding custom taxonomies (e.g. categories): developer.wordpress.org/plugins/taxonomies/
register_post_type()
documentation: developer.wordpress.org/reference/functions/register_post_type/register_taxonomy()
documenation: developer.wordpress.org/reference/functions/register_taxonomy/
We needed something a bit more though, as we wanted to customise the permalinks (i.e. auto-generated URL) of our Articles such that they are:
- Preceeded by the
article
slug, e.g.example.com/article/my-article-title
- Display the year and month before the post title, e.g.
example.com/article/2021/03/my-article-title
- Display a list of articles posted on the specified year and month if it was specified in the URL, e.g.
example.com/article/2021/03
would show all the articles posted in March 2021.
Want to find out how we did it? Then continue reading.
Continue reading