Wordpress custom theme development: single-{post_type}-{slug}.php hierarchy explained

38 views Asked by At

I am developing custom wordpress websites, the page hierarchy has been a hard concept for me to understand 100%.

I have a href

<a class="viewCar" id="15" href="/BWM/M4">........</a>

In the wordpress backend:
BMW is a page
M4 is a post

Now in my files, i have created a file called
single-{post_type}-{slug}.php

When i click the href, the URL should be www.car.com/BWM/M4 but i get www.car.com/M4

Secondly the page defaults to the index.php skipping all the other suggested pages from https://developer.wordpress.org/themes/basics/template-hierarchy

1

There are 1 answers

0
Vijay Hardaha On BEST ANSWER

Posts are different from pages, You need to check the page template documentation

If you just have to customize one page then you can use the page-{slug}.php way otherwise I will suggest you to use Custom page template option