Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress : integrate existing (generated) HTML pages

Tags:

wordpress

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...

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.

like image 916
Marc Polizzi Avatar asked Jan 02 '14 00:01

Marc Polizzi


3 Answers

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).

like image 54
Antwane Avatar answered Sep 28 '22 10:09

Antwane


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. :)

like image 44
Elie Andraos Avatar answered Sep 28 '22 08:09

Elie Andraos


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"
like image 21
Homer6 Avatar answered Sep 28 '22 09:09

Homer6