現在自作のプラグインを作成しています。
categoryの一覧で件巣表示の指定までは出来たのですが
ページナビゲーションを追加しようと思ったのですが
どう言う風にアプローチしていいのか思いつきません。
自分なりにやってみたのですがエラーも表示もされないので困っています。
ページナビゲーションを表示するにはどうすればよいですか?
参考ページ・サイトなどありましたらよろしくお願いします。
php
1//ショートコード追加 2function news_func($atts){ 3// ①引数が設定されていなければ get_option('posts_per_page') ← で管理画面で設定した、記事一覧で表示するページ数を取得 4 extract(shortcode_atts(array( 5 'page' => get_option('posts_per_page'), 6 ), $atts)); 7// ② ↓ 今現在のページ位置を取得 8$paged = (int) get_query_var('paged'); 9$args = array( 10// ③ページ数設定 11'posts_per_page' => $page, 12// ④ (int) get_query_var('paged') ← で取得した、$pagedを挿入 13'paged' => $paged, 14'orderby' => 'post_date', 15'order' => 'DESC', 16'post_type' => 'post', 17'post_status' => 'publish', 18'category_name' =>'news' 19); 20$the_query = new WP_Query($args); 21$html=<<<EOF 22<ul class="news_list"> 23EOF; 24if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); 25$title = get_the_title(); 26$time1 = get_post_time('M'); 27$time2 = get_post_time('d'); 28$time_array = explode(' ', $time); 29$p_link= get_the_permalink(); 30$html .=<<< EOF 31<li><span class="time_d">{$time2}</span><span class="time_m">{$time1}</span><a href="{$p_link}">{$title}</a></li> 32EOF; 33endwhile; 34endif; 35$navi_data=wp_pagenavi(); 36$html.=<<<EOF 37</ul> 38{$navi_data} 39EOF; 40wp_reset_postdata(); 41return $html; 42} 43add_shortcode('news', 'news_func');
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/06 13:32
2018/08/06 14:39