アトリエロワ

ループ記事を古い順に並べる【wordpress】

シンプルなループの一番上にquery_postsでorder=ascを入れる

<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>

↓

 <?php $posts = query_posts( $query_string . '&order=asc' ); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>

下記でも動作可能

<?php query_posts($query_string . '&order=asc'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>

「CPT UI」のtaxonomy-●●.phpで、「WP-PageNavi」プラグインが表示されない時

query_postsの範囲内に書く。
wp_reset_query();よりも前に書かないと、せっかくquery_postsで取得した条件がクリアされてしまう。

<?php query_posts($query_string . '&order=asc'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>

<?php the_title(); ?>

<?php endwhile; endif; ?>
//↓ここに記載
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
//↓リセット
<?php wp_reset_query();?>

件数指定

//↓10ページずつ表示
<?php $posts = query_posts( $query_string . '&order=asc&posts_per_page=10' ); ?>
<?php if (have_posts() ) : while ( have_posts() ) : the_post(); ?> 

<?php the_title(); ?>

<?php endwhile; endif; ?>
//↓ここに記載
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>
//↓リセット
<?php wp_reset_query();?>

HOME > wordpress設計術 > ループ記事を古い順に並べる【wordpress】

wordpress設計術

wordpress設計術