Wordpress帖子没有显示

时间:2015-09-17 16:49:18

标签: wordpress wordpress-theming

header.php - file

我是Wordpress脚本的新手,无法弄清楚我做错了什么?我的帖子没有显示

<nav class="subnav">
    <?php wp_nav_menu(array('theme_location' => 'menu')); ?>
</nav>

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
            <article>
                <div id="overview" class="tab">
                    <p><?php the_content(); ?></p>
                </div>
            </article>
        <?php endwhile;?>   

    <?php endif; ?>

3 个答案:

答案 0 :(得分:1)

在header.php中你应该添加这样的东西。

<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<?php wp_head(); ?>
</head>
<nav class="subnav">
    <?php wp_nav_menu(array('theme_location' => 'menu')); ?>
</nav>

在你的front-page.php或home.php或index.php **中包含带有wordpress特定功能get_header()的header.php,然后呈现你的菜单,帖子等:

<?php
get_header();
if (have_posts()) : while (have_posts()) : the_post(); ?>
    <article>
        <div id="overview" class="tab">
            <p><?php the_content(); ?></p>
        </div>
    </article>
    <?php endwhile;?>
<?php endif; ?>

请参阅this

**如果您对使用哪个php文件感到困惑,请研究WordPress hierarchy

答案 1 :(得分:0)

您可以在page.php或post.php上编写代码,否则您可以创建模板并放在代码下面并将页面分配给此模板。

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
            <article>
                <div id="overview" class="tab">
                    <p><?php the_content(); ?></p>
                </div>
            </article>
        <?php endwhile;?> 
    <?php endif; ?> 

答案 2 :(得分:0)

  

的header.php

<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>
<div id="page" class="hfeed site">
    <header>

        <nav class="subnav">
            <?php wp_nav_menu(array('theme_location' => 'menu')); ?>
        </nav>

            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                    <article>
                        <div id="overview" class="tab">
                            <p><?php the_content(); ?></p>
                        </div>
                    </article>
                <?php endwhile;?>   

            <?php endif; ?>

    </header><!-- #masthead -->

    <div id="content" class="site-content">
  

输出:

enter image description here

相关问题