WP_Query su savais argumentais ciklui rodyti WordPress įrašų turinį.
Galima lengvai paredaguoti savo pačių sukurtam įrašų tipui rodyti.
<?php
// Nurodyti argumentus ciklui
$args = array(
'post_type' => 'post',/ 'post', 'page', ar kiti tipai
'posts_per_page' => 10, // Kiek įrašų per puslapį rodyti (-1 visiems)
'post_status' => 'publish', // Rodyti tik paskelbtus įrašus
'orderby' => 'date', // Rikiuoti pagal paskelbimo datą
'order' => 'DESC', // Naujausius pirma
);
// 2. WP_Query
$custom_query = new WP_Query($args);
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="entry-content">
<?php the_content(); ?>
</div>
</article>
<?php endwhile;
// 4. Iš naujo nustatyti globalų kintamąjį
wp_reset_postdata();
else : ?>
<p><?php _e('No posts found.'); ?></p>
<?php endif; ?>