Wordpress ループ

wp ループメモ コピペ用

<div><ul> 1 // 表示件数の指定 ); $posts = get_posts( $args );foreach ( $posts as $post ): // ループの開始 setup_postdata( $post ); // 記事データの取得 ?> <li class="top-news"><a href="<?php the_permalink(); ?>"></a></li></ul></div>

Wordpress pre_get_postsアクションフック is_main_query()

functions.php ------- /*----- クエリ ------*/function my_pre_get_posts($query) { // 管理画面 or メインクエリ 以外には設定しない if(is_admin() || $query->is_main_query()) { # is_main_query => 現在のクエリがメインクエリかどうかを判断する。 r…

Wordpress WP_Query

'post', // 投稿記事だけを指定 'posts_per_page' => '3', // 最新記事を3件表示 ); $the_query = new WP_Query($args); if($the_query->have_posts()) : ?><section class="recentEntries"> <h1 class="type-C">最新記事</h1> <div class="entries"> have_posts…</div></section>