2016-08-26 3 views
0

안녕하세요 저는 블로그 게시물 중 일부가 포함 된 사용자 정의 페이지 (custom-page.php)를 만들려고하고 있지만 루프를 테스트 할 때 어떤 게시물도 보이지 않습니다. 내 사용자 지정 페이지 템플릿의 이름 만 h2로 반환합니다.Wordpress 사용자 정의 페이지, 게시물이 표시되지 않습니다.

두 개의 게시물이 이미 게시되었지만 표시되지 않습니다.

나는 사용자가 처음 내 사이트에 올 때 사용자가 방문하는 앞 페이지를 가지고 있으며 읽기 탭에서 설정을 변경하지 않았습니다.

Wordpress 코덱을 읽었으며 지금까지 해결 방법을 찾을 수 없습니다.

<?php 
get_header(); 
?> 

<div id="primary" class="content-area"> 
    <main id="main" class="site-main" role="main"> 


<h1>BLOG INDEX PAGE 

    BLOG INDEX PAGE</h1> 


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

    <h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> 
    <?php the_content(); ?> 
    <?php endwhile; else : ?> 

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

    <?php endif; ?> 

    </main><!-- #main --> 
</div><!-- #primary --> 


<?php 
get_footer(); 
?> 
+0

은 페이지 아래에는 사용자 지정 서식을 표시해야합니다. 방문 페이지 또는 블로그 페이지에 ??? –

+0

도 아니고, 내 게시물 중 일부의 스 니펫이 포함 된 페이지 일뿐입니다. –

+0

희망이므로 관리자 패널에서 바로 표시하도록 설정해야합니다. :) –

답변

1

이 코드를 따르십시오.

$newsQuery = newWP_Query('post_type=post','post_status=publish'); 
if ($newsQuery->have_posts()) { 
    while ($newsQuery->have_posts()) { 
     $newsQuery->the_post(); 
     echo get_the_title(); 
     echo get_the_excerpt(); 
    } 
} 

귀하의 전체 템플릿은 다음과 같습니다.

<?php 
get_header(); 
?> 

<div id="primary" class="content-area"> 
<main id="main" class="site-main" role="main"> 


<h1>BLOG INDEX PAGE 

BLOG INDEX PAGE</h1> 


    <?php 
    $newsQuery = new WP_Query('post_type=post','post_status=publish'); 
    if ($newsQuery->have_posts()) : while ($newsQuery->have_posts()) : $newsQuery->the_post(); ?> 

    <h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> 
    <?php the_content(); ?> 
    <?php endwhile; else : ?> 

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

<?php endif; ?> 

</main><!-- #main --> 
</div><!-- #primary --> 


<?php 
get_footer(); 
?> 
+0

이것은 나를 위해 일했습니다. 감사합니다! 지금 나는 그 문서를 찾을 필요가있다! –

0

wp admin에서 "Blog"라는 페이지를 만든 다음 theme-blog.php라는 테마 폴더에 파일을 만들고 아래 코드를 작성하십시오.

<?php 
get_header(); 
?> 

<div id="primary" class="content-area"> 
    <main id="main" class="site-main" role="main"> 

    <h1>BLOG INDEX PAGE</h1> 

    <?php 
    $args = array(
     'post_type'  => 'post', 
     'post_status' => 'publish', 
     'orderby' => 'id', 
     'order' => 'desc' 
    ); 
    $loop = new WP_Query($args); 
    if($loop->have_posts()) : 
    while ($loop->have_posts()) : $loop->the_post(); ?> 

     <h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> 
     <?php the_content(); ?> 

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


    </main><!-- #main --> 
</div><!-- #primary --> 


<?php 
get_footer(); 
?> 
0
 <?php 
      $args = array(
        'post_type' => 'post', 
        'post_status' => 'publish', 
        'posts_per_page' => -1, 
        'offset' => 0 
      ); 

      $the_query1 = new WP_Query($args); 

      if (count($the_query1->posts)>0) { 
       while ($the_query1->have_posts()) : $the_query1->the_post(); 
        get_template_part('loop-archive-template-location'); 
       endwhile; 


      } 
     ?> 
관련 문제