WordPress : integrate existing (generated) HTML pages

On one side I’ve an existing WordPress site.

On the other one, a bunch of existing and generated (actually some documentation pages) static HTML pages : several hundreds…

Read More

I’d like to integrate those existing HTML pages into the WordPress site.

There is no need to edit them from WordPress administration console. Simply to make them consistent with the overall look of the Web site (header, footer, etc…) and have the navigation (from WordPress pages) to these pages working.

Any idea if this possible and where should I look for some examples / tutorials / existing plugins.

Note 1 : I’ve full control over the generation process so the content of the generated pages can be adapted to the WordPress needs if required.

Note 2 : The whole existing HTML pages will be regenerated from time to time. So I’ll need to update my WordPress site accordingly.

Related posts

Leave a Reply

6 comments

  1. If you look at the .htaccess provided by wordpress:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    

    This configure the rewrite rules to ensure url will be pretty in your wordpress site. 2 interesting lines are:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    

    These lines tells the apache server to check if the requested file (1st line) or folder (2nd) exists. If it exists, it is returned, if not, the rewrite rules are applied (the blog is displayed as usual). So you can create a folder at the root of your web space (often www or htdocs) and upload generated files in it. These files will be accessible from your browser (http://www.yourdomain.com/yourfolder/yourfile.html).

    I think this is the simplest way to display statically generated content next to your blog pages. Using this, you will have to integrate header/footer/sidebar from your theme in the generated files.

    You also could use @Binod answer and use wordpress functions directly in your generated pages. Either by executing php code from *.html page, either by generating directly *.php files (if you can).

  2. Create a page template in your wordpress theme, say name it “page-external.php”
    your template page code should be like this:

    <?php
    /**
     * Template Name: External HTML Pages
     *
     */
     ?>
    <?php get_header(); ?>
    
    <?php if ( have_posts() ) :  ?>
        <?php while ( have_posts() ) : ?>
            <?php the_post(); ?>
            <?php the_content(); ?>
    <?php endif; ?>
    
    <?php get_footer() ?>
    

    This template is a basic wordpress loop that will display the content of the page that you will enter in the text editor of a wp page admin. (you can alter the template if you have any sidebars, widgets etc…)
    The trick is, in the text editor of your page admin you will add a wordpress shortcode with a parameter of the external page url to grab

    for instance,
    [externalpage href="http://www.mydomain.com/page"]

    to create a shortcode, it is easy and well documented in the wordpress api
    http://codex.wordpress.org/Shortcode_API

    in your shortcode, to grab the external page content, use get_file_content() php function or CURL if you prefer, but this should do it:

    function grab_externalpage_func(){
      return file_get_contents('http://www.mydomain.com/page');
    }
    add_shortcode( 'externalpage ', 'grab_externalpage_func' );
    

    So in the end, adding an external existing page, will be as simple as creating a new page template and adding the shortcode in the text editor and that’s it. and you still benefit from adding the page to the menu from the wordpress admin, along with the get_header() and get_ooter() just as every other page. 🙂

  3. You can use php_flag in a .htaccess file and use PHP’s built in auto append/prepend settings:

    php_value auto_prepend_file "docs_header.php"
    php_value auto_append_file "docs_footer.php"
    
    • loop over them .
    • get the content of each page .
    • insert each page’s body (stripped-tags) into db > wp_posts table and it’s type is page .
  4. This is an option:

    Run PHP from HTML: http://php.about.com/od/advancedphp/p/html_php.htm

    Then in the beginning of HTML files:

    <?php global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;    //to initialize WP environment
    require('<path to wp-load.php>' . 'wp-load.php'); ?>
    

    Then you can use the below WP functions in the appropriate places in HTML files:

    For top: http://codex.wordpress.org/Function_Reference/get_header

    For menu: http://codex.wordpress.org/Function_Reference/wp_nav_menu

    For bottom: http://codex.wordpress.org/Function_Reference/get_footer

    Notes:

    1. HTML files should be copied to the same domain as WordPress.

    2. Not tested.

  5. One of the options you have is to export the pages to a csv file and use “Really Simple CSV Importer” to import the content.

    It is easy to install and after installation will be available under Admin –> Tools -> Import. It will also give you a sample csv file and it will look like

    "post_id","post_name","post_author","post_date","post_type","post_status","post_title","post_content","post_category","post_tags","custom_field"
    

    I had a 300 page website which was built in dotnetnuke 5 way back 3-4 years and had great pain moving this to WordPress. So what I did is wrote a C# program which pulled all the dotnetnuke content from the db and emitted csv file. I grouped them into about 50 each I think.

    The only extra work we need to do is to generate the csv file. Also you might need to try this on a test installation first and then finally making sure you are happy with the results, you may need to run this on production.

    In my case I also had to edit the HTML & categories because I did not have them setup properly before. But if you are a little careful and plan your task, you can save a lot of work.