Wordpress Popular Postsを利用して、カスタムで作った固定ページのサイドの記事を閲覧回数順に表示させたいです。
<?php /* * Template Name: post_backnumber */ ?> <?php if (function_exists('wpp_get_mostpopular')) $count = 20; if (($_GET['c']) && (is_numeric($_GET['c']))) { if (($_GET['c'] > 0) && ($_GET['c'] <= 20)) { $count = $_GET['c']; } } header('Content-Type: application/json; charset='.get_option('blog_charset'), true); //-----[postのエントリー一覧取得] $args = array( 'range' => 'daily', 'limit' => 5, 'numberposts' => $count, 'offset' => 0, 'category' => null, 'orderby' => 'views', 'order' => 'ASC', 'include' => null, 'exclude' => null, 'meta_key' => 'category', 'meta_value' => null, 'post_type' => 'post', 'post_mime_type' => null, 'post_parent' => null, 'post_status' => 'publish' ); $posts = get_posts($args); $jsonAry = array(); $posts = wpp_get_mostpopular($args); foreach($posts as $post) : setup_postdata($post); $obj = new item(); $obj->id = $post->ID; $obj->title = $post->post_title; $obj->date = get_post_time('Y.m.d', true); $obj->category = get_post_meta($post->ID, 'category', true); $obj->lead = str_replace("\r\n", "</br>", get_post_meta($post->ID, 'lead', true)); $imgPost = get_post(get_post_meta($post->ID, 'main_v_1', true)); $obj->img = $imgPost->guid; $obj->caption = $imgPost->post_excerpt; array_push($jsonAry, $obj); endforeach; echo json_encode($jsonAry); //------------------------------ // JSONアイテム //------------------------------ class item { public $id; public $title; public $date; public $category; public $lead; public $img; public $caption; } ?>あなたの回答
tips
プレビュー