2014-05-21 5 views
1

모든 커스텀 포스트 타입 카테고리를 나열 할 수 있습니다. 그러나 거기에는 현재 카테고리의 게시물 만 나열하고 싶습니다.Wordpress 커스텀 포스트 타입리스트 카테고리 및 활성 카테고리 게시리스트

<?php 

$post_type = 'product'; 
$tax = 'product_category'; 
$tax_terms = get_terms($tax, array('orderby' => 'id', 'order' => 'ASC')); 
if ($tax_terms) { 
foreach ($tax_terms as $tax_term) { 
    $args = array(
     'post_type' => $post_type, 
     "$tax" => $tax_term->slug, 
     'post_status' => 'publish', 
     'posts_per_page' => - 1, 
     'orderby' => 'title', 
     'order' => 'ASC', 
     'caller_get_posts' => 1 
     ); 
    $my_query = null; 
    $my_query = new WP_Query($args); 

    if ($my_query->have_posts()) { 
     echo '<h3>' . $tax_term->name . '</h3>'; 
     while ($my_query->have_posts()) : $my_query->the_post(); 
     ?> 
     <p><i class="fa fa-angle-right" style="margin-right:5px;"></i><?php the_title(); ?>  </p> 

     <?php 
     endwhile; 
    } 
    wp_reset_query(); 
} 
} 

?> 

내 맞춤 게시물 유형의 모든 카테고리를 나열하지만, ​​현재 카테고리와 관련된 게시물뿐만 아니라 모든 게시물을 표시합니다.

다음은 활성 카테고리의 게시물을 표시하는 웹에서 발견 된 코드입니다. 나는 두 가지를 결합하려고했지만 php와 조건부 루프가 부족하여 작동하지 못하는 것 같습니다.

<?php 

$tax = get_query_var('tax'); // get current category 
$yourcat = get_category($cat); 

// now get all 'business' posts that are in the current custom taxonomy 
query_posts(array('post_type' => 'product', 'product_category' => $yourcat->slug)); 

if (have_posts()) : while (have_posts()) : the_post(); 
?> 
<h3><?php the_title(); ?></h3> 
<?php endwhile; endif; wp_reset_query(); ?> 

사람이 나를 도울 수 있고 두 가지 코드를 결합하거나 새로운 옵션을 알려주 길 바랍니다.

예를 들어 DVD 결과가 표시된 페이지에 다른 카테고리를 표시하는 사이드 바를 표시하고 사이드 바의 DVD 제목 아래에 DVD 카테고리의 제목 (게시물)을 표시 할 수 있습니다.

DVD

-title

-TITLE2

-TITLE3

BLU-RAY

CD

답변

0

게시물 유형을 등록 할 때 'hierarchical' => true을 했는가? 그것은 내가 희망이 도움이

// Custom Post_type Products 
    add_action('init', 'create_products'); 
    function create_products() { 
     $labels = array(
     'name' => _x('Products', 'post type general name'), 
     'singular_name' => _x('Product', 'post type singular name'), 
     'add_new' => _x('Add New', 'Product'), 
     'add_new_item' => __('Add new product'), 
     'edit_item' => __('Edit product'), 
     'new_item' => __('New product'), 
     'view_item' => __('View product'), 
     'search_items' => __('Search product'), 
     'not_found' => __('No products found'), 
     'not_found_in_trash' => __('No products found in Trash'), 
     'parent_item_colon' => '' 
    ); 

     $supports = array('title', 'editor', 'revisions', 'thumbnail', 'page-attributes'); 

     register_post_type('Products', 
     array(
      'labels' => $labels, 
      'public' => true, 
      'supports' => $supports, 
      'hierarchical' => true, 
      'menu_position' => 6, // places menu item directly below Posts 
      'menu_icon' => 'dashicons-cart', 
      'has_archive' => true 
     ) 
    ); 
    } 

당신의 functions.php에 이와 비슷한 보일 것이다

+0

그래, 나는 그것을 가지고 있지만 내가 원하는 활성 하나에 목록에있는 모든 범주를 보여주는 것입니다 그것의 밑에 포스트의 명부를 표시하십시오. – con322