2016-10-25 4 views
0

나는 Wordpress Category Page (category.php)에서이 하위 카테고리의 하위 카테고리와 게시물을 어떻게 얻을 수 있는지 알고 싶습니다.하위 카테고리 및 게시물 범주 페이지를 얻는 방법?

나는 아래 코드를 가지고 있으며, "echo 'test';"은 상위 카테고리의 게시물을 표시하고 싶습니다.

<?php 
$args = array('child_of' => get_query_var('cat')); 
$categories = get_categories($args); 

$numOfItems = 20; // Set no of category per page 
$page = isset($_GET['cpage']) ? abs((int) $_GET['cpage']) : 1; 
$to = $page * $numOfItems; 
$current = $to - $numOfItems; 
$total = sizeof($categories); 

echo '<ul class="cat-content">'; 
for($i=$current; $i<$to; ++$i) { 
    $category = $categories[$i]; 
    if($category->name) { 
     echo '<li><h2>'. $category->name.'</h2>'; 

     echo 'test'; 

     echo '</li>'; 
    } 
} 
echo '</ul>'; 

unset($category); 

?> 

답변

0

여기는 echo "test";입니다.

// The Query 
$args = array('post_type' => post, 'posts_per_page' => -1, 'cat' => $category->term_id); 
$the_query = new WP_Query($args); 

// The Loop 
if ($the_query->have_posts()) { 
    echo '<ul>'; 
    while ($the_query->have_posts()) { 
     $the_query->the_post(); 
     echo '<li><a href="'.get_permalink().'" >' . get_the_title() . '</a></li>'; 
    } 
    echo '</ul>'; 
    /* Restore original Post Data */ 
    wp_reset_postdata(); 
} else { 
    // no posts found 
} 
+0

안녕 @WordpressDave 고마워요. 그것은 나를 위해 일했습니다. 나는 또한 포스트 링크를 얻을 필요가있다. 이제 나는 제목 만 가지고 있습니다. 어떻게 링크를 얻을 수 있습니까? – mradovac

+0

안녕하세요. – WordpressDave