0
我正在寻找一种方法来注入一个类到一个自定义帖子类型的基础上关闭帖子归因于类别的div。将有三个类别;添加类到div包裹自定义帖子类型基于关闭帖子类别
电子书(类名CAT1)
信息图表(类名CAT2)
案例研究(类名CAT3)
这里是我的代码,到目前为止,调用自定义帖子类型。目前,该页面将所有帖子显示为最后一个类别 - 案例研究(cat3)。
<?php $loop = new WP_Query(array('post_type' => 'resources', 'posts_per_page' => -1)); ?>
<?php while ($loop->have_posts()) : $loop->the_post(); ?>
<?php
$post = $wp_query->post;
if (in_category('ebook', $post->ID)) { ?>
<div <?php body_class('tile scale-anm cat1 all end'); ?>>
<section class="small-12 medium-4 large-3 columns end">
<section class="grid">
<figure class="effect-sarah">
<img src="<?php the_field('img'); ?>" alt="img13"/>
<figcaption>
<h2>Resource</h2>
<p class="signika"><?php the_field('desc'); ?></p>
<p class="bold"><?php the_field('btnText'); ?></p>
<a href="<?php echo esc_url(get_permalink()); ?>" target="_blank"><?php the_field('btnText'); ?></a>
</figcaption>
</figure>
</section>
</section>
</div>
<?php
}
elseif (in_category('infographic', $post->ID)) { ?>
<div <?php body_class('tile scale-anm cat2 all end'); ?>>
<section class="small-12 medium-4 large-3 columns end">
<section class="grid">
<figure class="effect-sarah">
<img src="<?php the_field('img'); ?>" alt="img13"/>
<figcaption>
<h2>Resource</h2>
<p class="signika"><?php the_field('desc'); ?></p>
<p class="bold"><?php the_field('btnText'); ?></p>
<a href="<?php echo esc_url(get_permalink()); ?>" target="_blank"><?php the_field('btnText'); ?></a>
</figcaption>
</figure>
</section>
</section>
</div>
<?php
}
elseif (in_category('casestudy', $post->ID)) { ?>
<div <?php body_class('tile scale-anm cat3 all end'); ?>>
<section class="small-12 medium-4 large-3 columns end">
<section class="grid">
<figure class="effect-sarah">
<img src="<?php the_field('img'); ?>" alt="img13"/>
<figcaption>
<h2>Resource</h2>
<p class="signika"><?php the_field('desc'); ?></p>
<p class="bold"><?php the_field('btnText'); ?></p>
<a href="<?php echo esc_url(get_permalink()); ?>" target="_blank"><?php the_field('btnText'); ?></a>
</figcaption>
</figure>
</section>
</section>
</div>
<?php
}
?>
<?php endwhile; wp_reset_query(); ?>
@WheatBreak它太漂亮了....谢谢!那完美的工作!对此,我真的非常感激。还有一件事,我正在使用; data-rel =“cat1”来过滤页面上的项目,但我不认为这将工作了。有没有一种方法来过滤使用这个新系统的页面上显示的内容? – Furlong
这是模糊的...我有三个按钮,每个类别一个。一旦点击不在所选类别中的帖子类型隐藏。我使用data-rel,当它只是HTML时,它工作得很好。不是我转到自定义帖子类型。我需要找到一种方法来过滤按钮点击中的项目。提前致谢! – Furlong
不知道我是否完全理解,但是如果你使用jQuery,你可以像jQuery(“.cat1”)一样隐藏它们。hide()' – WheatBeak