2016-10-25 11 views
0

WordPressで独自のテンプレートを作成しましたが、ループのエントリが機能しません。私は、サブページの1つで作業をしたいと思います。私もエントリを追加しました。Wordpressループが動作しません

これは私のサブページのコードです。私を助けてください。私は何が間違っているのか分からない。コードの下に画像を追加しました。

<?php include 'header.php'; ?> 
    <main class="subpage-blog"> 
    <div class="subpage-banner"> 
     <div class="container"> 
      <h3>BLOG SIDEBAR</h3> 
      <div class="breadcrumbs"> 

      </div> 
     </div> 
    </div> 

    <aside class="side-menu col-md-4"> 
     <div class="search"> 
      <h4>Search blog</h4> 
      <input type="text" value="Search"> 
     </div> 
     <!-- .search --> 
     <div class="categories"> 
      <h4>Blog Categories</h4> 
      <ul class="categories-blog-ul"> 
       <li>Inspirtation</li> 
       <li>Work</li> 
       <li>Tech</li> 
       <li>Creative</li> 
      </ul> 
     </div> 
     <!--.categories--> 
     <div class="recent-posts"> 
      <h4>Recents posts</h4> 
      <ul> 

      </ul> 
     </div> 
     <!-- .recent-posts--> 
     <div class="tags-spot"> 
      <h4>Tags</h4> 
      <div class="tag"></div> 
     </div> 
     <!-- .tags-spot--> 
    </aside> 
    <!-- .side-menu--> 

    <article class="content"> 
     <div class="container"> 
      <?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
        <div class="news-box"> 
         <div class="news-list-content"> 
          <a href=""> 
           <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>      
           <?php the_content('czytaj dalej'); ?> 
          </a> 
         </div> 
         <!-- .news-list-content--> 
         <div class="image-box-news"> 
          <img src="<?=get_template_directory_uri(); ?>/images/ikona-wpisu.png" alt="" /> 
         </div> 
        </div> 
        <!-- .news-box--> 
       <?php endwhile; else: ?> 

       <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> 
<?php endif; ?> 
     </div> 
     <!-- .container--> 
    </article> 
    <!-- .content--> 
</main> 
<?php include 'footer.php'; ?> 

image

+0

私は、コードを実行し、ポストは示すことができる。

代わりに、あなたは完全に新しいクエリオブジェクトを作成し、そのようにそれにこれらの関数を呼び出すことになるでしょう。たぶんどこかのカスタムWP_Queryを実行するかもしれませんが、wp_reset_postdata()を呼び出すことを忘れてしまい、メインループが影響を受けます。 – ucheng

答えて

0

問題があることである:

if (have_posts()) : while (have_posts()) : the_post();

は、現在のページのhave_postsクエリを使用します。..それはそれはおそらくだけだろう何でもその現在のページテンプレートの内容を表示することを意味しますさあ。

<?php 
    $the_query = new WP_Query(array('posts_per_page' => 10)); //Create our new custom query 

    if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?> 
    <div class="news-box"> 
     <div class="news-list-content"> 
     <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>      
     <?php the_content('czytaj dalej'); ?> 
     </div> 

     <!-- all your other markup goes here.... --> 

    </div> 
<?php endwhile; else: ?> 
     <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> 
<?php endif; ?> 
<?php wp_reset_postdata(); //Restore the original postdata for this page, if needed later ?> 
+1

ありがとうGOD :) – Hazelek

関連する問題