2017-03-27 1 views
0

저는 주제 개발에있어 정말로 초보자입니다. front-page.php 안에있는 최근 10 개의 게시물과 더 좋은 방법이 있는지 잘 모르는 index.php 안에있는 모든 게시물을 페이지 단위로 가져오고 싶습니다.Wordpress 테마의 여러 ​​장소에서 게시물을 얻는 방법?

업데이트 : 모든 게시물을 표시하는 home page에 10 개의 게시물과 articles page이 있어야합니다.

이 접근 방식이 맞습니까? 그렇다면 어떻게해야합니까?

답변

0

몇 가지 조사를 한 후에 해결책을 찾았습니다.

처음에 나는 그때 Setting -> Reading을 변경, homearticles라는 2 페이지를 만들어 :

Front Page->home

Posts Page->articles

합니다. 다음 front-page.php의 내부

<?php 
    if (have_posts()) : while (have_posts()) : the_post(); 
     get_template_part('content', get_post_format()); 
    endwhile; endif; 
?> 

:

<?php 
// the query 
$wpb_all_query = new WP_Query(array('post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 10)); ?> 

<?php if ($wpb_all_query->have_posts()) : ?> 

    <!-- the loop --> 
    <?php while ($wpb_all_query->have_posts()) : $wpb_all_query->the_post(); ?> 
     <div class="post"> 
      <div class="col-xs-12 col-lg-6"> 
       <div class="panel panel-default "> 
        <div class="panel-body"> 
         <div class="col-xs-4"> 
          <a href="<?php the_permalink(); ?>"> 
           <?php if (has_post_thumbnail()) : ?> 
            <img src="<?php the_post_thumbnail_url(); ?>" alt=""> 
           <?php else: ?> 
            <img 
             src="<?php bloginfo('template_directory'); ?>/assets/image/placeholder.jpg" 
             alt=""> 
           <?php endif; ?> 
          </a> 
         </div> 
         <div class="col-xs-8"> 
          <div class="title"> 
           <a href="<?php the_permalink(); ?>"> 
            <h2><?php the_title(); ?></h2> 
           </a> 
          </div> 
          <div class="content"> 
           <p><?php echo substr(get_the_content(), 0, 320); ?>...</p></div> 
          <div class="read-more"> 
           <a href="<?php the_permalink(); ?>">Read More</a> 
          </div> 
         </div> 
        </div> 
       </div> 
      </div> 
     </div> 
    <?php endwhile; ?> 
    <!-- end of the loop --> 


    <?php wp_reset_postdata(); ?> 

<?php else : ?> 
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> 
<?php endif; ?> 

마침내 내가 원하는 정확히 어떤 방식으로 작동

는 내가하여 index.php articles 같은 페이지에 다음을 넣어.

관련 문제