Scenario 1. (see Figure 1.)
The easiest situation: You already have a .php based site, and you use a CSS file. Let’s say you installed WP in a subdirectory of your site (example.com/blog) and you want to update the NEWS section of your site with the posts from WP (See Fig.1)
So, basically you have an index.php at your root (example.com/index.php) and you need the posts into it from the example.com/blog.
1. First, let’s make the index file “WP aware”. Open your index.php file and at the very top, before anything else paste these lines applying the proper changes:
<?php require('./path-to-your-blog/wp-blog-header.php'); ?>
In our case it should look like:
<?php require('./blog/wp-blog-header.php'); ?>
2. Having the root index.php open, clean it up: delete all the text from the NEWS section and keep the rest. The News section should be just a bare
<div id="your-div-name">< /div>
(or a div class, depending on your structure).
3. Now we need to get The Loop into it. Open the index.php from the wordpress/wp-content/themes/classic/ folder.
The Loop starts here:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
and ends here:
<?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?>
Copy the whole Loop from the theme index and insert it into the div we just cleaned up. The Loop looks like this.
That’s all. You are done. Navigating your browser to the index.php of your root directory should show the X number of posts in the NEWS area – depending on the settings in your Options > Reading.
a) In The Loop that you just copied over there are several CSS id’s and classes: post, storytitle, meta, storycontent, h2. You may want to add them to your own stylesheet with the appropriate properties and values.
b) You will notice that clicking on the posts’ titles and “Comments” links it will take you to your blog at example.com/blog – displaying it with the Default (Kubrick) theme. If you want to avoid it, and you don’t want visitors to comment and/or see directly your blog, you can remove all the HTML anchor tags from around the title in The Loop. If there will not be comment, you can also delete the call for the comments-link:
<?php comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')); ?>
You may also want to remove the
< ?php the_category(',') ?> template tag (together with the “filed under” text), since it generates a link to the category archives page.
This is a multipage post: Page 1 Page 2 Page 3