2012-09-26 5 views
0

아래 코드로 나를 도울 수 있습니까? 그것은 잘 작동하지만 각 범주에 대한 코드 섹션을 작성하고 싶지 않습니다. 그래서 기본적으로 상위 카테고리를 한 번 표시하여 하위 카테고리로 표시하고 하위 카테고리는 모든 게시물을 나열합니다.Wordpress 그룹 게시글 카테고리

for 루프가 필요하지만 필기 방법을 잘 모르겠습니다. 이

<h4>2012</h4> 
    <ul class="news-coverage"> 
    <?php $cat_id = get_cat_ID('2012-media'); 
    $args=array(
     'cat' => $cat_id, 
     'post_type' => 'press', 
     'post_status' => 'publish', 
     'posts_per_page' => 100, 
     'caller_get_posts'=> 1, 
     'exclude' => 28, 
     'offset' => 9 

    ); 
    $new = new WP_Query($args); 
    $loop = new WP_Query($args); 
    while ($loop->have_posts()) : $loop->the_post(); 
    echo '<li><i class="foundicon-page"></i><strong>'; 
     the_title();echo '</strong><span>'; 
     the_date(); echo '</span>'; 
     the_content(); 
    echo '</li>'; 
    endwhile; ?> 

    </ul> 

    <h4>2011</h4> 
        <hr> 
    <ul class="news-coverage"> 
    <?php $cat_id = get_cat_ID('2011-media'); 
    $args=array(
     'cat' => $cat_id, 
     'post_type' => 'press', 
     'post_status' => 'publish', 
     'posts_per_page' => -1, 
     'caller_get_posts'=> 1, 
     'exclude' => 28 
    ); 
    $new = new WP_Query($args); 
    $loop = new WP_Query($args); 
    while ($loop->have_posts()) : $loop->the_post(); 
    echo '<li><i class="foundicon-page"></i><strong>'; 
     the_title();echo '</strong><span>'; 
     the_date(); echo '</span>'; 
     the_content(); 
    echo '</li>'; 
    endwhile; ?> 

    </ul> 
+0

당신은 [wordpress.stackexchange.com]에 대한 자세한 도움말을 찾을 수 있습니다 (http://wordpress.stackexchange.com). –

+0

질문에 서명 할 필요가 없습니다. 게시 할 때마다 자동으로 수행합니다. – Stephan

+1

@Stephan 위키 피 디아 컨디셔닝 – feeela

답변

0

당신은 갈 : (테스트하지)

<?php 
/* add category prefixes here */ 
$years = array('2011', '2012'); 

$output = ''; 

/* iterate over categories */ 
foreach($years as $year) 
{ 
    /* add the heading */ 
    $output .= sprintf('<h4>%s</h4>', $year); 

    /* setup current query/loop */ 
    $args = array(
     'cat' => get_cat_ID($year . '-media'), 
     'post_type' => 'press', 
     'post_status' => 'publish', 
     'posts_per_page' => 100, 
     'caller_get_posts' => 1, 
     'exclude' => 28, 
     'offset' => 9 
    ); 
    $loop = new WP_Query($args); 

    /* iterate over articles */ 
    $listItems = ''; 
    while($loop->have_posts()) 
    { 
     $loop->the_post(); 
     $listItems .= sprintf('<li><i class="foundicon-page"></i><strong>%s</strong><span>%s</span>%s</li>', 
      get_the_title(), 
      get_the_date(), 
      get_the_content() 
     ); 
    } 

    $output .= sprintf('<ul class="news-coverage">%s</ul>', $listItems); 
} 

echo $output; 
?> 
+0

도움에 감사드립니다 !! :) – Jenny

+0

또 다른 질문을하면, 사용자 정의 게시 유형에서 범주 이름과 연도별로 모든 범주 게시를 어떻게 나열 할 수 있습니까? – Jenny

관련 문제