I'm new to wordpress and can't figure out how wordpress link the html/php files on my customized theme to the permalinks of posts and pages. It's a bit long but please read all of them to see what i mean.
I have created a theme, created my index.php and style.css in it. Looks like when a post or a page is created, it has its own permalinks that looks something like this: /category/year/post
If i view the post on the browser and clicked the post that I've created, it serves the index.php even though the route /category/year/post is not set. The interesting part is that even though it serves index.php, it only displays the post that i clicked. Other post are not being displayed.
I'm thinking that index.php is the fallback file when the url requested does not exist. And index.php displays all the items (in this case the posts) that were retrieved on the database. So initially when i visited the post page, all the posts were retrieved that's why i see all of them. And now when i click one post it goes still in index.php but this time only one post is being retrieved that's why i only see one post. Is this the really the case? Can someone confirm this since this is just my observation.
Now this is the weird part. When i created a new file and named it anything that i want, in this case i named it single.php When i click a post, it doesn't serve index.php, it serves single.php. Now why is that? If index.php is the fallback file, then why is it serving single.php when i click a post (remember the post has this kind of link /category/year/post). I created another file and named it as double.php. When i click a post, it is still serving single.php. How does wordpress link a url to a file? I'm talking about the routing system when the client (browser) send a request to the server (apache).