Adding WordPress to an existing site

Tagged


Over at the WordPress Support Forums a user asked how he/she could incorporate WP into thier existing site.


That prompted me to finally get around to writing some tutorials on WP, and how to better integrate it into your existing site.


So here is the first installment.  Basically you can think of WP as a collection of functions or scripts that do specific things.  If you want to have your site title to be somewhere on the page, you simply type in:

This piece of code is all that is required on your part to achieve the desired affect.


So let's get down to brass tacks.  Say you have a site all ready to go, and you only want to use WP to power the text of your site; that is easy enough to do.


First lets set the stage.  For this example we will assume you have the following DIV's defined in your CSS:

  1. .header
  2. .menu
  3. .content
  4. .footer

Now all we will be concerned with in regards to WP is the .content DIV.  Here is where you will need to insert your functions.  I am going to assume that one would like to have the date, category, author name, time and comments in the .content area, following is how you would do that.

First things first


First you need to add this to the top of your index page:

I am assuming that you are using XHTML 1.1 here, I mean isn't everyone?  The WP to function.


Now, within the .content DIV add these functions:

<?php if ($posts) { foreach ($posts as $post) { start_wp(); ?>

This is the "motor" that starts WP off pulling your content from the database.  Alright next you would add this:

<?php the_date('','

','

'); ?>

Then one of these:

<?php the_title(); ?>

Now this bit of code calls to the database and grabs the title of your post, the way it is set up here is to make the title your permalink; a permalink is the permanent URI of this article.  I f you don't want it to be a link, leave off all the code.


Okay so far we have the date and the post title showing up in the .content DIV, now on to the actual post content.


Next we want to throw this function in:

<?php the_content(); ?>

That will call the body of your post and spit it out in the .content DIV.  Pretty straightforward huh?  Now we move onto the meta information, i.e. the category it was posted in (if any), the author who posted it (if you have more than one, or just like to see your name in lights), the time it was posted, and a link to any comments for that post.  Here is the function code to make that happen:

<?php link_pages("
Pages: ","
","number"); ?> :: <?php the_category(); ?> :: <?php the_author(); ?> @ <?php the_time(); ?> :: <?php show_post_count($post->ID, $before="Read Count (", $after=")"); ?> <?php comments_popup_link('Comments (0)', 'Comments (1)', 'Comments (%)'); ?>

This will spit out the appropriate values looking something like this:


Pages: (if multiple pages for post) :: TheCategory :: Mr Author @ 4:44 PM/AM :: Comments (0)


Next you need to add this code immediately after the above:
0) { add_count($p);}?>



That is all there is too it really, except that you will have to save this page with a .php extension(added 05.10.2004).  Now you will obviously want to style these, and add some sort of seperation between functions, like
's or throwing each funciton in it's own DIV nested within the .content DIV, it is really all up to you.


Let me know if this was helpful and if so, what other tutorials you would like to see on WP in the future.