2015-09-17 182 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; ?>