LoginSignup
0
0

More than 1 year has passed since last update.

PCとスマホで投稿記事の件数を変える

Posted at

やりたかったこと

WordPressの投稿記事を
・PCでは10件表示
・SPでは3件表示

funtions.phpではなく、メインループで。

PHP
<?php
  if( wp_is_mobile() ){
    $num = 3; //SPでの表示件数
  } else {
    $num = 10; //PCでの表示件数
  }
  $args = array(
  'post_type' => 'post',
  'posts_per_page' => $num,
  'order' => 'DESC'
  ); 
  $new_query = new WP_Query($args);
  if ($new_query->have_posts()) :
  while ($new_query->have_posts()) : $new_query->the_post();
?>
 
// ループの中身

<?php
  endwhile;
  wp_reset_query();
  endif;
?>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0