Wordpress - 页面内容无法显示

时间:2013-12-11 15:23:13

标签: php wordpress

我使用以下说明使用bootstrap 3创建了Wordpress主题:

http://www.creativewebdesign.ro/en/blog/wordpress/create-a-responsive-wordpress-theme-with-bootstrap-3-header-and-footer/

内容未在任何页面上显示。我不确定容器div是否有问题:

http://www.dawaf.co.uk/creative-mapping/

当我查看页面源时,测试文本不会显示。

的index.php

<?php
/**
 * The main template file.
 *
 * This is the most generic template file in a WordPress theme and one of the
 * two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * For example, it puts together the home page when no home.php file exists.
 *
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Wp_Bootstrap
 * @since Wp Bootstrap 1.0
 */

    // Gets header.php
    get_header();

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<?php the_title(); ?></h1>  
        <div class="entry">
            <?php the_content(); ?>
        </div><!-- entry -->
<?php endwhile; ?>
<?php endif; ?>

    // Gets footer.php
    get_footer(); 
?>

page.php文件

<?php
/**
 * The main template file.
 *
 * This is the most generic template file in a WordPress theme and one of the
 * two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * For example, it puts together the home page when no home.php file exists.
 *
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Wp_Bootstrap
 * @since Wp Bootstrap 1.0
 */

    // Gets header.php
    get_header();

    // Gets footer.php
    get_footer(); 
?>

2 个答案:

答案 0 :(得分:12)

我在代码中看不到<?php the_content(); ?>。这是显示内容所必需的。在这里,您可以看到Wordpress page about the_content。因此,请将<?php the_content(); ?>添加到index.php或更确切地添加到page.php文件或您要显示内容的位置。

修改

您还可以查看wordpress文件夹中的其他主题(二十几岁等)。在那里,您可以看到如何使用<?php the_content(); ?>

编辑2:

我忘了说这个。你也必须将它添加到你的文件中:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<?php the_title(); ?></h1>  
        <div class="entry">
            <?php the_content(); ?>
        </div><!-- entry -->
<?php endwhile; ?>
<?php endif; ?>

这将检查您是否有任何帖子或页面。如果是,它将显示它,如果不是,它将不显示任何内容。将其放在index.php<?php get_header(); ?>之间的<?php get_footer(); ?>

编辑3:

我在你的问题中看过你的编辑。我已经看到了这个错误。您打开了<?php代码两次。你可以这样:

<?php
/**
 * The main template file.
 *
 * This is the most generic template file in a WordPress theme and one of the
 * two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * For example, it puts together the home page when no home.php file exists.
 *
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Wp_Bootstrap
 * @since Wp Bootstrap 1.0
 */

    // Gets header.php
    get_header();
?>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<?php the_title(); ?></h1>  
        <div class="entry">
            <?php the_content(); ?>
        </div><!-- entry -->
<?php endwhile; ?>
<?php endif; ?>

<?php // Gets footer.php
get_footer(); 
?>

此代码应位于index.phppage.php

答案 1 :(得分:0)

在page.php中使用此代码:

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( is_front_page() ) { ?>
     <h2 class="entry-title"><?php the_title(); ?></h2>
<?php } else { ?>
    <h1 class="entry-title"><?php the_title(); ?></h1>
<?php } ?>

     <div class="entry-content">
       <?php the_content(); ?>
      <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
    <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
                </div><!-- .entry-content -->
            </div><!-- #post-## -->
     <?php endwhile; ?>