php Wordpress - 页面内容不显示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20522978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:15:41  来源:igfitidea点击:

Wordpress - page content not displaying

phpwordpress

提问by user3050023

I created a Wordpress theme with bootstrap 3 using the following instructions:

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

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

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

The content isn't displaying on any pages. I'm not sure if there is a problem with the container div:

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

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

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

The test text doesn't show up when I do view the page source.

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

index.php

索引.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

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

回答by roemel

I can't see <?php the_content(); ?>in your code. This is needed to display the content. Here you can see the Wordpress page about the_content. So add <?php the_content(); ?>to your index.phpor rather to your page.phpfile or there where you want to display your content.

<?php the_content(); ?>在你的代码中看不到。这是显示内容所必需的。在这里你可以看到关于 the_contentWordpress 页面。因此,添加<?php the_content(); ?>到您index.phppage.php文件中,或者添加到您的文件中,或者添加到您想要显示内容的位置。

EDIT:

编辑:

You also can look at the other themes in your wordpress folder (twentyten etc.). There you can see how <?php the_content(); ?>is used.

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

EDIT 2:

编辑2:

I forgot to say this. You have to add this to your file, too:

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

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

This will check if you got any posts or pages. If yes, it will display it, if no, it won't display anything. Put this to your index.phpbetween <?php get_header(); ?>and <?php get_footer(); ?>.

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

EDIT 3:

编辑 3:

I've seen your edit in your question. And I've seen the error. You opened the <?phptag twice. You can go this way:

我在你的问题中看到了你的编辑。我已经看到了错误。您打开了<?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(); 
?>

This code should be in your index.phpand in your page.php.

此代码应该在您的index.php和您的page.php.

回答by sourabh singh

Use this code in page.php:

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