The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Good screencast episode idea?

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #32550

    I had an idea last night for a possible future sreencast for Chris. Rather than email him directly I thought I’d post the idea here so he could see feedback from the rest of the community.

    So here’s my idea…

    Using jQuery to load posts and or content from a WordPress installation on a “static” PHP/HTML page/site. For example: he could show how to drop WordPress into a directory named /blog and then access the posts/content dynamically using jQuery’s $.load().

    I’ve been trying to accomplish this as a way to better understand PHP/jQuery/AJAX as well as WordPress. Rather than just letting WordPress “do everything” I’d like to take a more active role in the design and control of my site. I’ve built themes and understand that it’s easier to run a site using WordPress as the back end, but the fun part for me is making the cool things I learn here and elsewhere work, more than just seeing the finished product. It also seems like I can’t help making things harder than they need to be! :-)

    So far I’ve discovered that if you want to pull WordPress content into a page outside of the WordPress installation you need to include a few things at the top of the PHP file so that WordPress will run through it’s “boot process”. Otherwise you can’t access your content with the usual Loop and Template Tags. Here’s the code I’ve learned you need to start with:

    define('WP_USE_THEMES', false);

    // ONLY one of the following

    // setup The Loop

    After that you can use all the code usually used in a theme to display WordPress content. I did a little digging into wp-blog-header.php and wp-load.php because I had no idea what they did. Apparently wp-blog-header.php is used to load your theme AND call wp-load.php which is then responsible for loading wp-config.php and wp-settings.php. So they’re kind of like the boot scripts that you find in the /etc/rc.d folder on a *unix box. They get WordPress loaded and ready for querying. I’ve tested it both ways and it doesn’t seem to matter which you use. The only big difference I can see is that wp-blog-header.php calls the wp() function after it runs require_once(wp-load.php). So calling wp-load.php directly at the top of your PHP page would mean missing out on that call to wp(). wp() apparently sets up $wp_query but we’re so far beyond my realm of knowledge at this point I have no idea if that’s required. As I said my testing seems to work using either require() function above. Maybe you only need to run wp() when WordPress is running it’s theme? Questions like this are exactly why I think this would make a great screencast. I think Chris could totally put this into layman’s terms and make it enjoyable at the same time.

    Once you have the code above at the top of your PHP file you can then use something similar to the following code to load a list of your recent posts:

    I got most of the info above from the following sources:
    Codex: Integrating_WordPress_with_Your_Website
    Loading WordPress Posts With Ajax and Jquery
    WordPress Content on Other Pages
    What is the Constant WP_USE_THEMES For

    If you want to see a working example of what I’m talking about you can see what I’ve done so far on my site. All I ask is that you reserve judgement. Right now the site doesn’t do much. It’s a place for me to practice and implement what I’ve learned over the past two years. Right now all it really does is swap out div’s from index.html using click handlers. I also just got Nginx up and running with the FastCGI script PHP5-FPM so I’m pretty proud of that! I’ve been experimenting with the HTML5Boilerplate build script so if you want to view the source you need to view the site from this (unminified) directory.

    I completely understand that using WordPress like this is an extremely round about way of getting a blog on your site, but it sure is fun!! So let me (and Chris) know if you think this is a good idea for a screencast, or if you think I’m just crazy! I’ve learned so much from this site I’m really just looking forward to reading your thoughts and feedback.


    So im still a little confused, are you saying you could make a wordpress install without a data base and just with static pages? if so that would be really sweet because it would make hosting cost less.. the only thing i could think of is that updating would suck so bad.


    No, WordPress still operates and functions the same way it always has. Think about it more from the point of view of the theme. The method above removes the traditional “front end” from WordPress not the database “backend”. You build a site, or use an existing site, and then add in WordPress. Rather than the more traditional way of using WordPress where you install it and then build your site inside of it. The method described in my post above flips that process 180 degrees. Using AJAX calls like jQuery’s $.load() you can dynamically pull your post content from the WordPress install and display it wherever and however you like. Think of it like stuffing WordPress into a directory and using it only for storing your blog posts. You create the rest of your site without using WordPress pages or the menus or sidebars or widgets. That’s what I meant by “static”. Because the site isn’t being generated from the WordPress theme templates.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Other’ is closed to new topics and replies.