2017-02-17 5 views
1

방금 ​​새 페이지 템플릿을 만들고 카테고리 뉴스 만있는 모든 게시물을 인쇄하려고합니다.뉴스라는 카테고리의 게시물을 표시하는 방법

이 코드는 작동 할 때 워드 프레스 코덱스를 기반으로 사용되었습니다.

<?php 
    query_posts( 
     array ( 
      'post_type' => 'post', 
      'category_name' => 'news', 
      'category' => 1, 
      'posts_per_page' => 3) 
     );  
     // The Loop 

     while (have_posts()) : the_post(); 
      the_title(); 
      the_content();   
     endwhile; 
     // Reset Query 
     wp_reset_query(); 
?> 

어떻게 제목을 h1 태그에 넣고 내용을 div 상자에 넣을 수 있습니까?

나는이 시도하지만 나에게 구문 오류를주고있다 :
<h1><?php the_title(); ?></h1> 

당신이 도와 수 있기를 바랍니다.

+0

category_name 또는 category 중 하나를 사용하십시오. –

+0

@Kushal Shah 방금 두 개 중 하나를 제거했지만 여전히 아무것도 표시하지 않습니다. –

+0

당신은 다음과 같이 the_title ('

,'

'); –

답변

2
<?php global $post; 
    $args = array( 
     'posts_per_page' => 3, 
     'post_type' => 'post', 
     'category' => 1 
    ); 
    $myposts = get_posts($args); 
    foreach ($myposts as $post) : setup_postdata($post); 
the_title('<h1 class="entry-title">', '</h1>'); 
endforeach; 
     wp_reset_postdata(); 
    ?> 
+0

을 확인하십시오. 지원을 감사하십시오 –

+0

정말 고마워요. –

1

나는 인수의 매개 변수에서 category = 1을 제거해야한다고 생각합니다.

<?php 
global $post; 
$args = array( 
    'post_type' => 'post', 
    'posts_per_page' => 3, 
    'offset'=> 1, 
    'category_name' => 'news' 
); 
$myposts = get_posts($args); 
foreach ($myposts as $post) : setup_postdata($post); 
    the_title(); 
    the_content(); 

endforeach; 
wp_reset_postdata(); 
?> 

참고 : category_name에 카테고리의 슬러그를 사용하십시오. 또한 구문 오류가 발생했습니다

<?php the_content(); ?>"> //removed "> 

희망이 있습니다. 감사합니다

내가 코드를 업데이트 제목 & 콘텐츠 & H1 태그에 div 태그 추가 한
+0

제목을 HTML 태그로 묶고 싶지만 작동하지 않습니다. 내 편집 –

0

.

가 업데이트 된 코드를 찾아주세요 :

<?php 
    query_posts( 
     array ( 
      'post_type' => 'post', 
      'category_name' => 'news', 
      'posts_per_page' => 3 
      ) 
     );  
     // The Loop 

     while (have_posts()) : the_post(); ?> 
      <h1><?php the_title(); ?></h1> 
      <div class="wrap"> 
       <?php the_content(); ?> 
      </div> 
     <?php endwhile; 
     // Reset Query 
     wp_reset_query(); 
?> 

희망이 당신을 도울 것입니다.