I've started to develop my own theme in the past couple weeks (and extracting WP functionality here and there in the past year), and I'm finding the structure of the WP templates awful redundant.
Although that yes, technically, the blog starts somewhere higher above to load the WP functionality, the main WP_Query object, and some global variable preparation - I don't understand why every themes that I've stumbled upon so far splits the template files as:
- 404.php;
- archive.php;
- index.php;
- single.php;
- page.php;
- search.php;
- ... etc;
Those files basically duplicate a lot of PHP code to fetch the Header, Sidebar and Footer.
Wouldn't it be cleaner to have one (1) index.php
file that includes the Header, Sidebar, Footer... and within the index.php
file - you could decide how to show the content?
I'm not sure I understand the need to have separate files.
If you need to change the title in your <head>
tag, why not use the power of output-buffering (ob_start()
and ob_end_clean()
)to get the posts first / the page / the single post / the search results... Is there performance issues using this technique?
Could I run into problems if I wish to make my theme mobile-friendly, and readable by RSS feed readers?
-------------- EDIT:
I bring up this question because there is PHP methods that exists to detect in which section the user is visiting (ex: is_single()
, is_page()
, is_archive()
, is_home()
, etc...) and I would like to know if those could be used to achieve a central point for my index.php
file.