2015-09-17 185 views
0

header.php - 文件WordPress的帖子不显示

我是新来的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; ?> 
+0

你在哪里把这些代码? – Karthik

+0

如果您在主页中使用代码,请从设置中为主页设置最新帖子。 – srmilon

+0

@Karthik to header.php文件 – Viktor

回答

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

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> 

在你前面page.php文件或home.php或index.php的**包括用的header.php WordPress的特定功能get_header()然后渲染你的菜单,帖子等这样的:

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

**如果混淆使用,请学习的WordPress的PHP文件hierarchy

0

您CA n在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; ?>