모든 커스텀 포스트 타입 카테고리를 나열 할 수 있습니다. 그러나 거기에는 현재 카테고리의 게시물 만 나열하고 싶습니다.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
그래, 나는 그것을 가지고 있지만 내가 원하는 활성 하나에 목록에있는 모든 범주를 보여주는 것입니다 그것의 밑에 포스트의 명부를 표시하십시오. – con322