HTML到Wordpress仅适用于单个页面的正文

时间:2014-08-24 20:44:36

标签: php html wordpress

我有一个包含多个页面的HTML网站,我希望将博客作为其中一个页面包含在内。

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

是否可以定义具有硬编码页眉和页脚的Wordpress“主题”,但内容部分是否直接链接到Wordpress数据库中的Post?我只是希望将“Blog”链接到使用此单页运行Wordpress的URL,其余的将像往常一样保持纯HTML。

任何指向教程的链接都会很棒。我发现一对过于复杂,因为他们正在转换和整个网站。谢谢!

2 个答案:

答案 0 :(得分:0)

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

那里有更多样品,请查看

答案 1 :(得分:0)

我建议使用以下文件的主题:

  1. 的index.php
  2. single.php中
  3. style.css
  4. header.php(静态HTML)
  5. footer.php(静态HTML)
  6. 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(); ?>