Witam serdecznie, od razu przejdę do rzeczy. Piszę właśnie stronę i napotkałem problem, chcę aby na stronie głównej było wyświetlane max. 5 wpisów,(to udało mi się uzyskać) jeżeli będzie więcej niż 5 ma zostać utworzona strona do której będę mógł bezpośrednio przejść wybierając numer strony.
Kod pętli:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- TYTUŁ STRONY -->
<?php
/*
Tutaj wypiszemy wszystkie wpisy
Użyjemy do tego obiektu klasy WP_Query
*/
$args = array(
'posts_per_page' => 5,
'post_type' => 'post'
);
$posts_query = new WP_Query( $args );
if ( $posts_query->have_posts() ) {
while ( $posts_query->have_posts() ) {
$posts_query->the_post();
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
echo "<a href='" . get_permalink() . "'>";
?>
<a href="<?php the_permalink();?>">
<div class="akt-mini animated fadeIn">
<?php
echo "<img src=" . $url . " />";
?>
<div class="akt1-mini">
<div class="align-font-left-box"><?php the_title(); ?></div>
<?php the_author(); ?>
</div>
</div>
</a>
<?php
}
}
wp_reset_postdata();
?>
<?php endwhile; endif; ?>