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!
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
I would suggest having a theme with the following files:
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(); ?>