【发布时间】:2017-07-26 17:42:21
【问题描述】:
我正在寻找一种方法,将一个类注入到一个 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(); ?>
【问题讨论】:
标签: php jquery html css wordpress