首页 > 解决方案 > 引导轮播显示自定义分类而不是自定义帖子

问题描述

我目前有一个用于显示自定义帖子类型的循环,从自定义字段到带有指标的引导轮播。问题是,自定义帖子类型有 2 个类别(自定义分类法 company_testimonial 和 agent_testimonial),我只想显示其中一个。

我已经迷失了

<?php
$post_objects_testimonials = get_field('choose_testimonials');
if ($post_objects_testimonials):
?>
<!-- Section testimonials -->
<section class="testimonials">
<div class="container">
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<?php
    $count = count($post_objects_testimonials);
    for ($i = 0; $i < $count; $i++) {
?>
<li data-target="#carouselExampleIndicators" data-slide-to="<?php

    echo $i;

--------

?>" <?php
        if ($i == 0) {
?>
<div class="active">
<?php
        }
?>
</li>
<?php
    }
?>
</ol>
<div class="carousel-inner">
<?php
    $count = 0;
?>
<?php
    foreach ($post_objects_testimonials as $post):
?>
<?php
        foreach ($post_objects_testimonials as $post):
?>
<?php
            setup_postdata($post);
            $test_image     = get_field('test_image');
            $test_image_url = $test_image['url'];
            $test_image_alt = $test_image['alt'];
?>
<div class="carousel-item
<?php
            if ($count == 0) {
                echo ' active';
            }
?>">
<div class="row">
<div class="col-lg-11 mx-auto">
        <?php
            if (get_field('description')):
?>
<p class="quote-paragraph">
<?php
                the_field('description');
?>
</p>
<?php
            endif;
?>
<?php
            if (get_field('description') && get_field('job_title') && get_field('name')):
?>
<p class="quote-author">
<strong><?php
                the_field('name');
?></strong>
<?php
                the_field('job_title');
?>
<?php
                the_field('company');
?>
</p>
<?php
            endif;
?>
</div>
<?php
            $count++;
?>
</div>
</div>
<?php
        endforeach;
?>
</div>
<div class="arrow-icons">
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
</section>
<?php
        wp_reset_postdata();
?>
<?php
    endforeach;
?>
<?php
endif;
?>

我希望显示分类 company_testimonial 但忽略 agent_testimonial

标签: phpwordpresstwitter-bootstrap

解决方案


看起来您正在使用高级自定义字段来保存存储在“choose_testimonials”中的内容。根据我在此处看到的内容,我假设该特定字段的高级自定义字段内的设置不正确。

如果不是这种情况,则您使用的包装器或 WordPress 模板不正确。我们需要更多关于这些事情的信息来提供帮助!


推荐阅读