0

I am making a carousel for my AMP page, and I want to re-use the code, so I made it into a template, however, I am having the problem with changing ID on the array for category value, I would like to be able to insert the template code, and just select the category, so I can re-use it nicely, instead of copy-pasting it like a maniac. I tried some things in the last few days, and most of them work when the code is on the same page as the carousel, however, when it's as a template, it breaks it. This is the code I used to build it, and I would like to learn how to change the "category" => 1 values.

<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 &raquo;</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>

1 Answer 1

-1

If you are looking to change value of categories, you can just take a vairable instead of taking constant value and increment based on category!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.