Index.php defines how to display a loop of posts
category.php does the same thing but it's included when displaying a category archive
WordPress will look for the most specific template it can find, and work backwards until it finds a file that exists, where index.php is the most generic. So long as
So long as the template implements the main loop, it will function correctly. Which template is used has no bearing on the kind of post displayed. Templates are purely visual/aesthetic
The actual fetching of the posts, be they category posts, a single individual post, a page, a date archive etc, is done using query vars, and is done long before WordPress picks which template implements theto use.
- Your rewrite rules will run some regex to extract some bits of data from the URL.
- This data is then sanitised and used as query variables ( the details of which you can see in the codex WP_Query page )
- Based on these query variables, checks are made, and internal values such as 'is_main_loop' and 'is_search' etc are filled in.
- Now that the query vars are done, we have all we need to execute the main loop, so it is instantiated and setup ready
- Based on the checks earlier, the template loader now runs. It refers to the main query object, and follows the template hierarchy
- The most 'specific' template found is loaded. If this template has implemented the main loop ( as it should do ), the posts loaded earlier are now displayed.
- If the most specific template isn't found, it falls back to the next most specific, and repeats until it reaches the most 'generic' template aka index.php. index.php is required for a theme to work so it will always be present.
There is no difference between loading index.php and category.php or archive.php etc.
So why do we have category.php? Well we only need index.php, but maybe we want our category archives to look different from our main looplisting? Maybe we want the site to look different for listings from individual posts? Rather than having a big if else setup in index.php e.g. if listing do this, it will function correctlyelse if category listing do that, etc WordPress has the template heirarchy.
Templates are purely about visual and html markup. They are presentation, and have nothing to do with what the data is or where the data comes from.
See this handy flowchart to see what WordPress will use:
Finally an analogy to demonstrate your questions problem:
You're running a company that makes tables, square tables, and employ 5 carpenters and a designer who likes square tables.
One day you hire a new designer and a carpenter. This new designer likes circular tables. You notice that after giving the new carpenter these designs that he produces circular tables. What is so special that this carpenter makes circular tables, when the others will make circular tables too if I fire him?