我正在尝试在WordPress上使用Reveal.js(https://github.com/hakimel/reveal.js/),帖子是每张幻灯片的内容。
我已经在幻灯片上正确显示了帖子,但是我无法找到一种方法来包装标签中具有相同类别的帖子。
基本上,我当前的代码看起来像这样:
<section class="section chapter-1 ">
</section>
<section class="section chapter-1 ">
</section>
<section class="section chapter-1 ">
</section>
<section class="section chapter-2 ">
</section>
<section class="section chapter-2 ">
</section>
但我需要它看起来像这样:
<section id="category-1">
<section class="section chapter-1 ">
</section>
<section class="section chapter-1 ">
</section>
<section class="section chapter-1 ">
</section>
</section>
<section id="category-2">
<section class="section chapter-2 ">
</section>
<section class="section chapter-2 ">
</section>
</section>
这是我的index.php代码:
<div class="reveal content-area">
<div id="content" class="slides site-content" role="main">
<?php if ( have_posts() ) : ?>
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php twentythirteen_paging_nav(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div><!-- #content -->
</div><!-- #primary -->
...依此类推更多“章节”和更多类别
如果您注意到第二个代码示例已分组并包含在具有类别名称ID的section标记中。
答案 0 :(得分:0)
你可以这样做,或者有一个带有类别的数组
<?php
$args = array( 'category' => 1 );
get_posts($args);
?>
<section id="category-1">
<?php
if (have_posts()) : while (have_posts()) : the_post();
?>
<section class="section chapter-<?php the_ID()?> ">
the_content();
</section>
<?php
endwhile; endif;
?>
</section>
<?php
wp_reset_query();
$args = array( 'category' => 2 );
get_posts($args);
<section id="category-2">
if (have_posts()) : while (have_posts()) : the_post();
<section class="section chapter-<?php the_ID()?> ">
the_content();
</section>
endwhile; endif;
</section>
wp_reset_query();
?>