I just want to display posts by number value by user given in "pocet" parameter [oblubene-clanky pocet=""]
. This code isn't working. I tried and edited this solution with no results. So, what is wrong?
function my_shortcode( $atts ) { ?>
<div class="list_posts mt-5">
<?php
$atts = shortcode_atts( array( 'pocet' => '' ), $atts, 'oblubene-clanky' );
$args = array(
'posts_per_page' => $atts['pocet'],
'orderby' => 'date',
'order' => 'DESC',
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) : $query->the_post();
if ( isset( $atts['pocet'] ) ) : ?>
<div class="pb-4 d-flex ">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<a href="<?php the_permalink(); ?>"><img src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'thumbnail' ); ?>" alt="<?php the_title(); ?>"></a>
</div>
<div class="pl-5">
<h6><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h6>
<p><?php the_excerpt(); ?></p>
<p class="small m-0"><?php echo get_the_date(); ?></p>
</div>
</div>
<?php
endif;
endwhile;
wp_reset_postdata();
endif; ?>
</div>
<?php
}
add_shortcode( 'oblubene-clanky', 'my_shortcode' );