Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Are website articles really hand coded and adjusted manually as with this exercise?

For websites with many articles do they really sit there in a html file doing this? I would've thought they'd type it out somewhere more convenient then link it in to display the whole article, am i wrong?....just, Wordpress sites and blog sites seem waaaaaaaaaaay more easier for article pages than making them yourself in this way.

1 Answer

Brendon Butler
Brendon Butler
4,254 Points

There are many ways that they achieve these pages without having to code every article by hand. Here are a few:

PHP Includes - these allow you to essentially have a modular website. Each piece of your page is its own module.

To accomplish this, you can build a placeholder site with one PHP include that may be, for example, whatever is in your article.

If you have a lot of pages that use the same header and footer you can have a header.php and footer.php (and any other modules you want). Then you dont have to rewrite the header and footer every time

website.php
<html>
    <?php include 'modules/header.php'; ?>
    <article>
        <h1>Example Header</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin dapibus vulputate turpis, ac pharetra velit ullamcorper eu. Nulla nec elementum lorem, eu luctus urna. Nunc lobortis ipsum at quam blandit tristique.

        ...</p>
    </article>
    <?php include 'modules/footer.php'>
</html>

There are many ways to use PHP to do this. I used to do this on my own website, but there are better ways. I would suggest starting with this method to learn PHP and expand your HTML skills.

Query Strings - I use it on my site for my projects, YouTube uses it for their videos.

It's a bit more complicated, and probably difficult to fully understand, but the easiest way in my opinion is to use HTML5 and JavaScript to build your site based off whatever the query is. That way you only have one webpage, but it can have an infinite amount of different articles or whatever.

There's a GET and POST tutorial in the HTML course that can shed some light into this.

If you want to build your own site like this, I would start by getting the basics of HTML done first, then learn PHP, start using the first method. Then, when you've got that down, I'd move on to HTML5 and Javascript using queries.

Brendon Butler
Brendon Butler
4,254 Points

Oh, and I'm not exactly sure how YouTube does it. But I have a JSON file that JavaScript accesses to retreive the data for the page. This isn't the best for sites with lots of data, but for my purposes it works great.

You can also have the website save itself in the browser's cache so every time the website is opened it doesnt have to parse all the data. Saving time, processing power, and data usage.