Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Wordpress Theme Layout Idea

Featured Replies

Just a fair warning: I've got one WP-based site live, and it's only one of three themes that I've created (first two were test themes to learn the process)... So I am definitely not an 'expert' in any way regarding WP themes.

 

But.... I had a strange idea last night that I can't seem to get out of my head. Maybe it's a good idea, maybe not, I haven't tried it (yet). Before I do though, maybe someone could give me some feedback regarding this?

 

The majority of themes for WP involve an 'index.php' file in such a way that it simply includes (or 'calls', if you prefer that term) each component of the site. Such as the following example taken from the Starkers theme:

<?php get_header(); ?>

<?php get_template_part( 'loop', 'index' ); ?>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

 

Then the 'header.php', content (in this case, 'loop.php', which in turn determines the type of content to display), 'sidebar.php' and 'footer.php' files are simply combined into a single file and processed by the PHP server to create the HTML document a browser displays...

 

Instead of editing the 'header.php', 'sidebar.php' and 'footer.php' files separately, since these are generally the same across all pages, why not simply build these into the index file and call 'loop.php' dynamically for different content? Is there any reason not to do this (other than adding conditions to use different headers / footers)? This train of thought should drop the overall file count quite a bit if applied throughout the theme.

 

To me, the current standard just seems more complex than it needs to be... Well, there's that, and the fact that I don't really like the way the opening and closing tags for elements are located in different files.

Edited by ZaLiTH

Its a valid point you make but I think one of the main reasons for doing it like this is that you can reuse the header and footer, which on most websites will be consistent and won't differ from page to page. Then you can have many page templates using the same header and footer with different layout/content outside of the loop.

Also say if you had the header and footer coded in index.php and then had another page template aswell, to edit the header or footer you would have to edit both index.php and the second page template rather than just one file (eg header.php) imagine doing this if you had many page templates.. a lot more time consuming.

  • Author

Its a valid point you make but I think one of the main reasons for doing it like this is that you can reuse the header and footer, which on most websites will be consistent and won't differ from page to page. Then you can have many page templates using the same header and footer with different layout/content outside of the loop.

 

Also say if you had the header and footer coded in index.php and then had another page template aswell, to edit the header or footer you would have to edit both index.php and the second page template rather than just one file (eg header.php) imagine doing this if you had many page templates.. a lot more time consuming.

The first part of your post makes sense, I don't quite agree with your logic in the second part though... Unless a theme has different headers for different pages (which can still be accounted for after combining the files in question), I don't really see any reason to not attempt it.

 

 

Take a simple site in standard structure (excluding meta.php / comments.php / etc):

- index.php

- header.php

- footer.php

- home.php

- single.php

- page.php

 

Vs my idea for a condensed structure (also excluding extra files):

- index.php (combined with header and footer)

- home.php

- single.php

- page.php

 

 

Following what you said: having to edit the header or footer and a page template.. With the standard structure, you'd have to edit the header.php (or footer.php) and the template (page.php for example). That involves editing two files. With a condensed structure, index.php and page.php, also two files. However, if you need to change the header, footer and page. Standard structure: 3 files, condensed structure: 2 files.

 

At the end of the day, what I'm proposing is to simply have the page layout called into index.php between the 'header' and 'footer' areas; instead of the 'header', 'page layout' and 'footer' all called separately. This probably won't make much difference to the development time involved in making a WP theme, but I expect site maintenance at a later point would be greatly simplified.

 

This whole idea actually came up after I explained to a programmer friend of mine who's done work in PHP before (straight PHP dev though, no WP), and he was horrified at the way the themes are structured. I'm simply exploring options to make it simpler to work with.

 

I do still plan to try make a theme based on this concept though, just to see for myself if it is worth while. When I do, I'll post my results back here (and if it works, maybe share a blank template for others to use).

Yeah go for it, see how it works for you. As far as I know there is no reason why you can't do it..

 

Let me explain my second point again a bit clearer. Say if you have this structure:

- index.php

- home.php

- single.php

- page.php

- page-1.php

- page-2.php

- page-3.php

- page-4.php

- page-5.php

 

And you want to change one thing in header.php (which is now coded into each page template) then you will have to edit many files, whereas if you call the header file in each page then you only need to edit one file - header.php. It saves time when you are using a lot of page templates

Edited by itodd

  • Author

Eh... I just realised something, and it's a problem I didn't think of until now. In trying to explain why the header would not be in every page template, I ended up explaining why my theory wouldn't work.

 

The point of this exercise is not to have the header in every template, it's to only have it in 'index.php'. But alas, therein lies a fatal flaw.. :( The index.php file is not used throughout every page the site would display, and that's a vital point I overlooked.

 

Amazing how such a small detail makes such a big difference... Oh well, in order to be old and wise we must first be young and stupid (and ask many questions). :)

Ah ok, I miss understood what you meant, I thought you meant have the header and footer in each page template rather than only on index.php, but yes, index.php may not be used for all of your pages on your site.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.