2014-03-05 25 views
0

我已經創建了自定義模板並使用此模板添加了頁面。 但循環無法正常工作:循環返回文章頁碼(顯然不存在)。 任何人都可以提供一個建議嗎?WordPress的。循環不能在模板文件中工作

的header.php我在自定義模板使用(循環工作正確的index.php文件與此頭):

<head> 
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/css/styles.css" /> 
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/css/ptsans.css" /> 
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/css/ptserif.css" /> 
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/css/neucha.css" />  
<script type="text/javascript"></script> 
<meta charset="<?php bloginfo('charset'); ?>" /> 
<meta name="viewport" content="width=device-width" /> 
<title><?php wp_title(''); ?><?php if(wp_title('', false)) { echo ' |'; } ?> <?php bloginfo('name'); ?></title> 
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" /> 
<?php wp_head(); ?> 

環路是基本太:

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

      <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 

       <div class="entry-conten clr"> 
        <?php the_content(); ?> 
        <?php wp_link_pages(array('before' => '<div class="page-links clr">', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>')); ?> 
       </div><!-- .entry-content --> 

       <footer class="entry-footer"> 
        <?php edit_post_link(__('Edit Page', 'wpex'), '<span class="edit-link">', '</span>'); ?> 
       </footer><!-- .entry-footer --> 
      </article><!-- #post --> 

      <?php comments_template(); ?> 
     <?php endwhile; ?> 

希望有人可以解釋我做錯了什麼。

+1

你是否在任何地方調用wp_footer()?你真的應該使用wp_enqueue_style,而不是粘貼在文件頂部的css includes中。 –

+0

感謝您的回覆,我將從現在開始使用wp_enqueue_style。是的,我在本頁使用wp_footer() – user1820686

回答

1

沒有錯。技術上頁面是一個帖子(在儀表板中檢查the_ID()),使用不同的模板。實際上你可以使用相同的代碼。也許只是標籤不是頁面的最佳主意。測試嘗試最簡單的循環

<?php while (have_posts()) : the_post(); the_content(); endwhile; // THE LOOP ?> 
+0

好的,我明白了。我已經嘗試使用你的代碼片段並得到了相同的結果 - 只有1個帖子在循環中。在這種情況下我如何獲得所有帖子? – user1820686

+0

只是用args建立第二個正常的wp查詢,並添加另一個循環來顯示它們 –

+0

好吧,我明白了。謝謝 – user1820686