我正在为我的AMP页面制作一个旋转木马,我想重用代码,所以我将其制作成了一个模板,但是,我在更改类别值数组上的ID时遇到了问题,我希望能够插入模板代码,只需选择类别,这样我就可以很好地重用它,而不是像疯子一样复制粘贴它。在过去的几天里,我尝试了一些方法,当代码与旋转木马位于同一页面时,大多数方法都会起作用,然而,当它作为模板时,它会破坏它。这是我用来构建它的代码,我想学习如何更改“category”=>1值。
<div class="category-slider">
<?php
$args = array( \'posts_per_page\' => -1, \'offset\'=> 1, \'category\' => 1);
$pageposts = get_posts( $args ); ?>
<amp-base-carousel id="cat-carousel-8"
attr-name="(min-width: 1200px) valueOne, (min-width: 300px) valueTwo, defaultValue"
layout="responsive"
width="1200px"
height="500px"
visible-count="3"
advance-count="1" >
<?php foreach ( $pageposts as $post ) : setup_postdata ( $post ); ?>
<div layout="flex-item">
<div class="category-slider-containter">
<a class="category-slider-image" href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
<h2 class="category-slider-item"><?php the_title(); ?></h2>
<div class="category-slider-content"><?php the_excerpt(); ?></div>
<p><a class=\'read-more\' href="<?php the_permalink(); ?>">Read More »</a></p>
</div>
</div>
<?php
endforeach;
wp_reset_postdata();?>
<button slot="next-arrow" class="carousel-next btn-next" aria-label="Next"></button>
<button slot="prev-arrow" class="carousel-prev btn-prev" aria-label="Previous"></button>
</amp-base-carousel>
</div>