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