Use WordPress as a PHP Framework for Your Static HTML Pages112
WordPress is a great solution for creating blog, but that isn’t all it can do. The incredible power and simplicity of this platform allows you to create personal web pages or entire web sites in minutes, using all the functions of this environment with minimal effort.
With WordPress, you can develop an entire professional web site (with or without a blog) even though you know just a little bit of HTML! Read on to see how.
The Whole Platform in a Regular PHP Page
WordPress works on PHP pages, but if you only know the HTML please don’t worry. For our purpose, that’s enough.
Create a file named test.php and save it in the root of your blog (the blog root is the same directory where you see the files wp-config.php, wp-login.php or wp-blog-header.php).
Now, with your editor, edit test.php and add this line to the top of the file:
<?php include(’wp-blog-header.php’); ?>
And you’re done already! This great but simple command make availables in your page all the features, the commands and the functions of the WordPress platform!. To check that it’s working, add some more code, e.g:
<?php include(’wp-blog-header.php’); ?> <html> <body> <div class=”name”><?php bloginfo(’name’); ?></div> <div class=”description”><?php bloginfo(’description’); ?></div> </body> </html>
Then save the file and load it up in your browser.
If you’re working on the web (and didn’t make a mistake!), you can see your page from the main directory of the blog (so, if the blog address is http://www.yourblog.com,then the link will be http://www.yourblog.com/test.php).
In this test page you will see the name and the description of your blog, taken directly from the WordPress database.
Write a Complete Webpage in 10 Seconds
For an example of making good use of this, the first utilization of the WordPress platform would surely be to write a complete web page with the same themes as your blog in a few seconds.
Create a new test.php page within this code:
<?php include(’wp-blog-header.php’); ?> <?php get_header(); ?> <!– Put here your personal contents in HTML or PHP –> … <!– End personal contents –> <?php get_footer(); ?>
In this page, using the get_header() and the get_footer() functions, you copy into your page the same header and footer as your blog, so you must only write the content of the page! Great!
If you want include the sidebar too, just modify the code:
<?php include(’wp-blog-header.php’); ?> <?php get_header(); ?> <!– Put here your personal contents in HTML or PHP –> … <!– End personal contents –> <?php get_sidebar(); ?> <?php get_footer(); ?>
Really, really easy! With the get_sidebar() row you take the blog sidebar from WordPress and paste it into your web page!
If you want know all the functions of the WordPress platform (Which you can now use), you can begin to read here.
Why (and when) When To Use WordPress on a Webpage
Anything you can do with a WordPress function or a WordPress plugin can be included in your personal web pages, so, when you include the wp-blog-header.php page in your web page, you are using WordPress as a great framework to develop web sites.
At this point a good question would be: “but why don’t I use a simple WordPress page with a custom template?”
Yes, you can do it, and in some situations this is the better solution.
The big advantage of this system is that you have complete control over the file. You can choose to embed only one plugin, one script etc. You can leave out the sidebar, pull in a different one, or do whatever you want. You could do this using WordPress Page Templates, but they are more hassle than using this one line of code is.
What Can I Do With This Technique?
Some scenarios where it could be useful to write a web page using the ‘Wordpress injection’ are:
- When I have a blog and I want expand it into a blog + web site.
- When I love a WordPress theme and I want it for my website.
- When in my blog I want to implement AdSense for search results on my own page.
- When I want add some little web application into my existent blog or i want include any non-blog area.
At this point, if you are interested, begin to program your web page, include the wp-blog-header.php page in your code and start testing the power of the WordPress framework! And if you have any doubts or feedback about this article, I would love to hear it.
Enjoy this post? You should follow me on Twitter!