4 개의 부트 스트랩 탭이있는 페이지가 있습니다. 각 탭에는 다른 카테고리의 맞춤 게시물 유형 게시물이 포함됩니다. 4 카테고리, 4 탭. 이것은 in_category()를 사용하여 정말 쉽습니다; 하지만 어떤 이유로 첫 번째 탭만 필터링 할 수 있습니다. 나머지 3 개의 탭에는 게시물이 전혀 표시되지 않습니다. 카테고리 필터의 루프가 작동하지 않습니다.
나의 접근 방식이 질문을 참조하십시오 여기 Creating if statements to filter posts by category from cpt in wordpress저널 내 CPT입니다 아카이브 - journal.php에서 코드입니다. 고급 사용자 정의 필드를 사용하고 있습니다.
PHP
<!-- Tab panes -->
<div class="tab-content">
<?php if (have_posts()) : ?>
<!-- cambridge winter college -->
<div role="tabpanel" class="tab-pane active" id="tab1">
<!-- accordian -->
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<?php $entry_count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php if (in_category('cambridge-winter-college')) : ?>
<?php $entry_count++; ?>
<!-- entry -->
<div class="entry">
<div class="col-lg-3 date">
<time class="cbp_tmtime"><span><?php the_field('day'); ?></span><br> <span><?php the_field('date'); ?><sup><?php the_field('suffix'); ?></sup> <?php the_field('month'); ?></span> </time>
<div class="cbp_tmicon"></div>
</div>
<div class="panel-heading panel-head col-lg-9">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse-cw-<?php echo $entry_count; ?>">
View <?php the_field('day'); ?>'s journal entry
</a>
</div>
<div id="collapse-cw-<?php echo $entry_count; ?>" class="panel-collapse collapse in col-lg-12 pull-right">
<div class="panel-body col-lg-9 pull-right">
<div class="row">
<div class="col-lg-12 entry-text">
<aside class="col-lg-6 pull-right flexbox-2">
<div class="schedule" >
<?php $table = get_field('schedule');
if ($table) {
echo '<table>';
if ($table['header']) {
echo '<thead><tr>';
echo '';
foreach ($table['header'] as $th) {
echo '<th>';
echo $th['c'];
echo '</th>';
}
echo '</tr>';
echo '</thead>';
}
echo '<tbody>';
foreach ($table['body'] as $tr) {
echo '<tr>';
foreach ($tr as $td) {
echo '<td>'.$td['c'].'</td>';
}
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
} ?>
</div>
<?php if (the_field('fun_fact')) { ?>
<div class="fun-fact" style="">
<?php the_field('fun_fact'); ?>
</div>
<?php } ?>
</aside>
<div class="flexbox-1">
<?php the_field('entry_text'); ?>
</div>
</div>
</div>
<div class="row carousel-wrapper">
<div id="carousel-cw-<?php echo $entry_count; ?>" class="carousel slide" data-ride="carousel">
<div class="carousel-inner" role="listbox">
<?php if (have_rows('slider')) : ?>
<?php $image_count = 0 ?>
<?php while (have_rows('slider')) : the_row(); ?>
<?php $image_count++; ?>
<?php if (get_sub_field('image')) { ?>
<div class="item <?php if ($image_count == 1) echo 'active' ?>">
<img src="<?php the_sub_field('image'); ?>" title="">
<figcaption><?php the_sub_field('caption'); ?></figcaption>
</div>
<?php } ?>
<?php endwhile; ?>
<?php else : ?>
<?php // no rows found ?>
<?php endif; ?>
<a class="left carousel-control" href="#carousel-cw-<?php echo $entry_count; ?>" role="button" data-slide="prev">
<span class="fa fa-chevron-left glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-cw-<?php echo $entry_count; ?>" role="button" data-slide="next">
<span class="fa fa-chevron-right glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<!--/carousel -->
</div>
</div>
</div>
</div>
</div>
<!-- /entry -->
<?php endif; ?>
<?php endwhile; ?>
</div>
<!--/accordian -->
<div class="terminator"></div>
</div>
<!--/cambridge winter college -->
<!-- oxford summer 1 -->
<div role="tabpanel" class="tab-pane" id="tab2">
<!-- accordian -->
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<?php $entry_count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php if (in_category('oxford_summer_college_1')) : ?>
<?php $entry_count++; ?>
<!-- entry -->
<div class="entry">
<div class="col-lg-3 date">
<time class="cbp_tmtime"><span><?php the_field('day'); ?></span><br> <span><?php the_field('date'); ?><sup><?php the_field('suffix'); ?></sup> <?php the_field('month'); ?></span> </time>
<div class="cbp_tmicon"></div>
</div>
<div class="panel-heading panel-head col-lg-9">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse-os1-<?php echo $entry_count; ?>">
View <?php the_field('day'); ?>'s journal entry
</a>
</div>
<div id="collapse-os1-<?php echo $entry_count; ?>" class="panel-collapse collapse in col-lg-12 pull-right">
<div class="panel-body col-lg-9 pull-right">
<div class="row">
<div class="col-lg-12 entry-text">
<aside class="col-lg-6 pull-right flexbox-2">
<div class="schedule" >
<?php $table = get_field('schedule');
if ($table) {
echo '<table>';
if ($table['header']) {
echo '<thead><tr>';
echo '';
foreach ($table['header'] as $th) {
echo '<th>';
echo $th['c'];
echo '</th>';
}
echo '</tr>';
echo '</thead>';
}
echo '<tbody>';
foreach ($table['body'] as $tr) {
echo '<tr>';
foreach ($tr as $td) {
echo '<td>'.$td['c'].'</td>';
}
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
} ?>
</div>
<div class="fun-fact" style="">
<?php the_field('fun_fact'); ?>
</div>
</aside>
<div class="flexbox-1">
<?php the_field('entry_text'); ?>
</div>
</div>
</div>
<div class="row carousel-wrapper">
<div id="carousel-os1-<?php echo $entry_count; ?>" class="carousel slide" data-ride="carousel">
<div class="carousel-inner" role="listbox">
<?php if (have_rows('slider')) : ?>
<?php $image_count = 0 ?>
<?php while (have_rows('slider')) : the_row(); ?>
<?php $image_count++; ?>
<?php if (get_sub_field('image')) { ?>
<div class="item <?php if ($image_count == 1) echo 'active' ?>">
<img src="<?php the_sub_field('image'); ?>">
<figcaption><?php the_sub_field('caption'); ?></figcaption>
</div>
<?php } ?>
<?php endwhile; ?>
<?php else : ?>
<?php // no rows found ?>
<?php endif; ?>
<a class="left carousel-control" href="#carousel-os1-<?php echo $entry_count; ?>" role="button" data-slide="prev">
<span class="fa fa-chevron-left glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-os1-<?php echo $entry_count; ?>" role="button" data-slide="next">
<span class="fa fa-chevron-right glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<!--/carousel -->
</div>
</div>
</div>
<!-- </div> -->
</div>
<!-- /entry -->
<?php endif; ?>
<?php endwhile; ?>
</div>
<!--/accordian -->
<div class="terminator"></div>
</div>
<!--/oxford summer 1 -->
<!-- oxford summer college 2 -->
<div role="tabpanel" class="tab-pane" id="tab3">
<!-- accordian -->
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<?php $entry_count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php if (in_category('oxford_summer_college_2')) : ?>
<?php $entry_count++; ?>
<!-- entry -->
<div class="entry">
<div class="col-lg-3 date">
<time class="cbp_tmtime"><span><?php the_field('day'); ?></span><br> <span><?php the_field('date'); ?><sup><?php the_field('suffix'); ?></sup> <?php the_field('month'); ?></span> </time>
<div class="cbp_tmicon"></div>
</div>
<div class="panel-heading panel-head col-lg-9">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse-os2-<?php echo $entry_count; ?>">
View <?php the_field('day'); ?>'s journal entry
</a>
</div>
<div id="collapse-os2-<?php echo $entry_count; ?>" class="panel-collapse collapse in col-lg-12 pull-right">
<div class="panel-body col-lg-9 pull-right">
<div class="row">
<div class="col-lg-12 entry-text">
<aside class="col-lg-6 pull-right flexbox-2">
<div class="schedule" >
<?php $table = get_field('schedule');
if ($table) {
echo '<table>';
if ($table['header']) {
echo '<thead><tr>';
echo '';
foreach ($table['header'] as $th) {
echo '<th>';
echo $th['c'];
echo '</th>';
}
echo '</tr>';
echo '</thead>';
}
echo '<tbody>';
foreach ($table['body'] as $tr) {
echo '<tr>';
foreach ($tr as $td) {
echo '<td>'.$td['c'].'</td>';
}
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
} ?>
</div>
<div class="fun-fact" style="">
<?php the_field('fun_fact'); ?>
</div>
</aside>
<div class="flexbox-1">
<?php the_field('entry_text'); ?>
</div>
</div>
</div>
<div class="row carousel-wrapper">
<div id="carousel-os2-<?php echo $entry_count; ?>" class="carousel slide" data-ride="carousel">
<div class="carousel-inner" role="listbox">
<?php if (have_rows('slider')) : ?>
<?php $image_count = 0 ?>
<?php while (have_rows('slider')) : the_row(); ?>
<?php $image_count++; ?>
<?php if (get_sub_field('image')) { ?>
<div class="item <?php if ($image_count == 1) echo 'active' ?>">
<img src="<?php the_sub_field('image'); ?>">
<figcaption><?php the_sub_field('caption'); ?></figcaption>
</div>
<?php } ?>
<?php endwhile; ?>
<?php else : ?>
<?php // no rows found ?>
<?php endif; ?>
<a class="left carousel-control" href="#carousel-os2-<?php echo $entry_count; ?>" role="button" data-slide="prev">
<span class="fa fa-chevron-left glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-os2-<?php echo $entry_count; ?>" role="button" data-slide="next">
<span class="fa fa-chevron-right glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<!--/carousel -->
</div>
</div>
</div>
</div>
</div>
<!-- /entry -->
<?php endif; ?>
<?php endwhile; ?>
</div>
<!--/accordian -->
<div class="terminator"></div>
</div>
<!--/oxford summer college 2 -->
<!-- cambridge summer college -->
<div role="tabpanel" class="tab-pane" id="tab4">
<!-- accordian -->
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<?php $entry_count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php if (in_category('cambridge_summer_college')) : ?>
<?php $entry_count++; ?>
<!-- entry -->
<div class="entry">
<div class="col-lg-3 date">
<time class="cbp_tmtime"><span><?php the_field('day'); ?></span><br> <span><?php the_field('date'); ?><sup><?php the_field('suffix'); ?></sup> <?php the_field('month'); ?></span> </time>
<div class="cbp_tmicon"></div>
</div>
<div class="panel-heading panel-head col-lg-9">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse-cs-<?php echo $entry_count; ?>">
View <?php the_field('day'); ?>'s journal entry
</a>
</div>
<div id="collapse-cs-<?php echo $entry_count; ?>" class="panel-collapse collapse in col-lg-12 pull-right">
<div class="panel-body col-lg-9 pull-right">
<div class="row">
<div class="col-lg-12 entry-text">
<aside class="col-lg-6 pull-right flexbox-2">
<div class="schedule" >
<?php $table = get_field('schedule');
if ($table) {
echo '<table>';
if ($table['header']) {
echo '<thead><tr>';
echo '';
foreach ($table['header'] as $th) {
echo '<th>';
echo $th['c'];
echo '</th>';
}
echo '</tr>';
echo '</thead>';
}
echo '<tbody>';
foreach ($table['body'] as $tr) {
echo '<tr>';
foreach ($tr as $td) {
echo '<td>'.$td['c'].'</td>';
}
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
} ?>
</div>
<div class="fun-fact" style="">
<?php the_field('fun_fact'); ?>
</div>
</aside>
<div class="flexbox-1">
<?php the_field('entry_text'); ?>
</div>
</div>
</div>
<div class="row carousel-wrapper">
<div id="carousel-cs-<?php echo $entry_count; ?>" class="carousel slide" data-ride="carousel">
<div class="carousel-inner" role="listbox">
<?php if (have_rows('slider')) : ?>
<?php $image_count = 0 ?>
<?php while (have_rows('slider')) : the_row(); ?>
<?php $image_count++; ?>
<?php if (get_sub_field('image')) { ?>
<div class="item <?php if ($image_count == 1) echo 'active' ?>">
<img src="<?php the_sub_field('image'); ?>">
<figcaption><?php the_sub_field('caption'); ?></figcaption>
</div>
<?php } ?>
<?php endwhile; ?>
<?php else : ?>
<?php // no rows found ?>
<?php endif; ?>
<a class="left carousel-control" href="#carousel-cs-<?php echo $entry_count; ?>" role="button" data-slide="prev">
<span class="fa fa-chevron-left glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-cs-<?php echo $entry_count; ?>" role="button" data-slide="next">
<span class="fa fa-chevron-right glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<!--/carousel -->
</div>
</div>
</div>
</div>
</div>
<!-- /entry -->
<?php endif; ?>
<?php endwhile; ?>
</div>
<!--/accordian -->
<div class="terminator"></div>
</div>
<!-- /cambridge summer college -->
<?php endif; ?>
</div>
<!--/tab content -->
긴 코드 덤프 죄송하지만 기본적으로 동일하며 4 번 복사됩니다. 정말로 나는 여기서 무엇이 잘못되었는지를 볼 수 없다. 모든 조언을 크게 주시면 감사하겠습니다.
에서 print_r'의 결과를 공유하시기 바랍니다 (get_querried_object()); [문 워드 프레스에 CPT에서 카테고리 게시물을 필터링 할 경우 만들기]의' – BlueSuiter
가능한 중복 (http://stackoverflow.com/question/43312949/creating-if-statements-to-filter-posts-by-cpt-in-wordpress) –
두 번째 탭 동안 print_r을 삽입했습니다. 내가 이것을 가지고 : 치명적인 오류 : 정의되지 않은 함수를 호출 get_querried_object() – vincentieo