2010-11-29 9 views
0

나는 워드 프레스에 같은 범주별로 그룹화 포스트 제목을 표시하려면 :Wordpress - 범주별로 게시물을 표시하는 방법?

종류 : 사과 - 게시물 제목 하나 - 게시물 제목 두 - 포스트 제목 ....

카테고리 : 오렌지 - 게시물 제목 1 - 게시물 제목 2 - 게시물 제목 ....

플러그인이나 카테고리 위젯이 아닌 코드를 작성하려면이 코드가 필요합니다.

+1

가능한 복제본 [Wordpress에서 카테고리의 게시물을 게시 하시겠습니까?] (http://stackoverflow.com/questions/1735959/display-posts-from-a-category-in-wordpress) – Stephen

답변

1

이 "카테고리 페이지로 아카이브의"를 만드는 것과 비슷하며 다음 코드를 사용하여 수행 할 수 있습니다

<?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
    <div class="post" id="post-<?php the_ID(); ?>"> 
    <h2><?php the_title(); ?></h2> 
     <div class="entry"> 
      <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?> 

      <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?> 

     </div> 
    </div> 
    <?php endwhile; endif; ?> 

    <!-- Category Archive Start --> 
    <ul class="catArchive"> 
    <?php 
    $catQuery = $wpdb->get_results("SELECT * FROM $wpdb->terms AS wterms INNER JOIN $wpdb->term_taxonomy AS wtaxonomy ON (wterms.term_id = wtaxonomy.term_id) WHERE wtaxonomy.taxonomy = 'category' AND wtaxonomy.parent = 0 AND wtaxonomy.count > 0"); 

    $catCounter = 0; 

    foreach ($catQuery as $category) { 

     $catCounter++; 

     $catStyle = ''; 
     if (is_int($catCounter/2)) $catStyle = ' class="catAlt"'; 

     $catLink = get_category_link($category->term_id); 

     echo '<li'.$catStyle.'><h3><a href="'.$catLink.'" title="'.$category->name.'">'.$category->name.'</a></h3>'; 
      echo '<ul>'; 

      query_posts('cat='.$category->term_id.'&showposts=5');?> 

      <?php while (have_posts()) : the_post(); ?> 
       <li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></li> 
      <?php endwhile; ?> 

       <li><a href="<?php echo $catLink; ?>" title="<?php echo $category->name; ?>">More <strong><?php echo $category->name; ?></strong></a></li> 
      </ul> 
     </li> 
     <?php } ?> 
    </ul> 
    <!-- Category Archive End --> 

참고 위의 코드 그들과 관련된 게시물이 의지 만 표시 카테고리, 그렇지 않으면 건너 뛸 것입니다.

또한 각 카테고리 아래 마지막 5 개의 게시물 만 표시됩니다. showposts 변수 다음에 숫자를 변경하여 변경할 수 있습니다. 당신이 10 개 게시물 표시 곳

query_posts('cat='.$category->term_id.'&showposts=5'); 

하나에 : 예를 들어, 당신은 변경 될 수

query_posts('cat='.$category->term_id.'&showposts=10'); 

대체 맨 처음에 루프에 위의 라인을 그리고 당신은 종류에 의해 작동하는 '아카이브해야 "페이지.

관련 문제