HTML到Wordpress的主体只有一个页面



我有一个HTML网站有多个页面,我想包括一个博客作为这些页面之一。

页眉和页脚永远不需要Wordpress动态地定义其组成部分(例如,我不需要从Wordpress加载导航项,因为这些已经预定义并且永远不会更改)。

是否有可能定义一个Wordpress"主题",有硬编码的页眉和页脚,但有内容部分直接链接到Post的Wordpress数据库?我只是想让"博客"链接到一个运行Wordpress的url,其余的将像往常一样保持纯HTML。

任何教程的链接将是伟大的。我发现了一对过于复杂的夫妇,因为他们是转换和整个网站。谢谢!

这是WP的指南:

<?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;
?>

这里有更多的示例,请查看

我建议用以下文件创建一个主题:

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

index.phpstyle.css是唯一的文件,你需要有一个WordPress主题。

你的style.css只需要这样你就可以声明你的主题。它只需要在顶部加上这段:

/*
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
*/

然后,您的header.phpfooter.php可以有您的静态HTML内容。

然后在index.phpsingle.php中你可以包括这些函数,这将包括你的HTML从你的页脚。

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

那么你的single.php可以是这样的:

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

你的index.php可以是这样的:

<?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(); ?>

相关内容

最新更新