Question

I code alot of wordpress themes, and one thing I really like to do whenever I code them is make sure my code is very clean, organized, and easy to find things in.

One way I like to make sure my code is Organized is I like to use PHP Include like this:

<?php include(TEMPLATEPATH . '/includes/top-container.php'); ?>

So if I had a website that look like this:

<div class="top-container>
...
</div>
<div class="tagline">
...
</div>
<div class="slider">
...
</div>
<div class="middle-container">
     <div class="content">
     ...
     </div>
     <div class="sidebar">
     ...
     </div>
</div>
<div class="bottom-container">
...
</div>

My final code will look something like this:

<?php get_header(); ?>

<?php include(TEMPLATEPATH . '/includes/tagline.php'); ?>

<?php include(TEMPLATEPATH . '/includes/slider.php'); ?>

<?php include(TEMPLATEPATH . '/includes/middle-container.php'); ?>

<?php get_footer(); ?>

So I am spiting my code into parts and including them. I love how organized my code is, but I was wondering if this was good practice? Will this slow my website down, though I am pull necessary parts?

Was it helpful?

Solution

Generally, multiple calls to read files will produce more I/O load than a single file. You can, however, eliminate that issue using cache.

In my opinion, the best practise is whatever is easier to read, and maintain. Worry about optimization when you need to, and not before.

OTHER TIPS

you should come up with alternative solution to reduce the no. of includes in your code, so many includes may reduce speed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top