A Long Blog with All the Blogs on One Page

The blog is live and the blog looks cool but it's all on one page. And we're gonna have millions of blogs and we can't just put it all on one page. Also it's more practical to read a blog page then trying to sift through one page of endless blog content to find the blog you want to read. So we are gonna make each blog have it's own page. So I'm going to create a new folder to put the blog pages in and call it "blogs". Now I create files for my blogs and call it the permalink of the blog with the ".php" extention. Now I cut and paste the HTML from the index.php blogs into the cooresponding blog files.

Now that they're is a file for each blog it's time to use those files to create the content for the blog pages. For these blogs to have their own pages they need to have their own GET requests. Using the special $_GET variable we can get the permalinks for the blogs from the user. The user sends a request for example the last blog 'A Basic Bitch Blog' the route would be "/?blog=basic-bitch-blog"

Now it's time to take the code to a new level. It's time to go down the rabbit hole now. We need to include the blog content if our blog GET value is defined. So first we check if the user has requested a blog. If so we use the permalink value and include the file for the blog content. Now I'll add my first conditional in the blog.

<?php if($_GET['blog']){ include("blogs/".$_GET['blog'].".php") } ?>

Now each blog has it's own page which is cool but no one is gonna know how to get to the blogs so we need to start making links to the blogs. So I'll go back to the featured blog area and uncomment the continue reading link then replace the # with "?blog=blog-about-building-a-blog". Now I can go to the featured blog and continue reading. But there is no way to get back to the home page. The title of the website is a link and I'll replace the # with /. Now I can get back to the home page by clicking title of the site.

The featured blog is still showing when I go to a blog page. But I only want the featured blog to appear on the home page. So I will add another conditional that checks if the user is on the home page. And with PHP we use the empty function to check if the $_GET value is empty.

<?php if(empty($_GET)) : ?>

Now the blog is like a real blog with separate pages for each blog and our featured blog content area is dynamic. Stay tuned for the next blog were we add some blog previews so not only the users, but Google can see the blogs.

Comments