0
votes

I have an HTML website with multiple pages, and I want to include a blog as one of these pages.

The header and footer will never need Wordpress to define its parts dynamically (for instance, I don't need the navigation items to load from Wordpress, as these are already pre-defined and won't ever change).

Is it possible to define a Wordpress "theme" that has hard coded header and footer, but have the content section linked directly to Post's in the Wordpress database? I simply want to have the "Blog" link to a url that is running Wordpress with this single page, the rest will remain pure HTML as usual.

Any links to tutorials would be great. I have found a couple that are overly complex because they are converting and entire website. Thanks!

2
It is possible of course, you host WP in a sub-directory then create a theme with header.php, footer.php etc. hard-coded. Basically you only need the WP loop includednin the theme.Szőke Péter
Would you use WordPress functions to access database (post) or you'd use yours?hex494D49
@hex494D49 I would be accessing it from the Wordpress database that will be installed on my own hosting service.Kyle Begeman
@SzőkePéter From what you have described, it sounds like it is possible. I have read a bit about the loop that is required so that is probably the best place for me to startKyle Begeman

2 Answers

0
votes

It's in WP's codex:

<?php 
/* Short and sweet */
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
?>

<?php
require('/the/path/to/your/wp-blog-header.php');
?>

<?php
$posts = get_posts('numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) : setup_postdata( $post ); ?>
<?php the_date(); echo "<br />"; ?>
<?php the_title(); ?>    
<?php the_excerpt(); ?> 
<?php
endforeach;
?>

There are more samples there, check it out

0
votes

I would suggest having a theme with the following files:

  1. index.php
  2. single.php
  3. style.css
  4. header.php (static HTML)
  5. footer.php (static HTML)

index.php and style.css are the only files you need to have a WordPress theme.

Your style.css is need only so you can declare your theme. All it needs is this at the top:

/*
Theme Name: NAME OF YOUR THEME
Theme URI: http://SOME_URL.com
Author: You
Author URI: http://YOU.com
Description: bla, bla, bla
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

*/

Then, your header.php and footer.php can have your static HTML content.

Then in index.php and single.php you can include these functions, which will include your the HTML from your footer.

<?php get_header(); ?>
// YOUR PHP OR HTML
<?php get_footer(); ?>

Then your single.php can be something like:

<?php get_header(); ?>

<h2><?php the_title(); ?></h2>
<div class="entry-content">
    <?php the_content(); ?>
</div>
<?php get_footer(); ?>

Your index.php can be something like:

<?php get_header(); ?>
<?php 
if ( have_posts() ) {
    while ( have_posts() ) {
        the_post(); 
        <h2><?php the_title(); ?></h2>
        <div class="entry-content">
            <?php the_content(); ?>
        </div>
    } // end while
} // end if
?>

<?php get_footer(); ?>