提交 b08bbfba 编写于 作者: J jianbo

调整文章分类的加载

上级 a4fdb347
......@@ -50,8 +50,23 @@ class RAM_REST_Categories_Controller extends WP_REST_Controller{
// Register our schema callback.
'schema' => array( $this, 'get_public_item_schema' ),
) );
register_rest_route( $this->namespace, '/' . $this->resource_name.'/ids', array(
// Here we register the readable endpoint for collections.
array(
'methods' => 'GET',
'callback' => array( $this, 'get_categories_ids' ),
//'permission_callback' => array( $this, 'get_item_permissions_check' )
),
// Register our schema callback.
'schema' => array( $this, 'get_public_item_schema' ),
) );
}
public function postSubscription($request)
{
global $wpdb;
......@@ -185,6 +200,17 @@ class RAM_REST_Categories_Controller extends WP_REST_Controller{
}
public function get_categories_ids()
{
$categoriesId =get_option('wf_display_categories');
$result['Ids'] =$categoriesId;
$response = rest_ensure_response($result);
return $response;
}
public function post_item_permissions_check($request)
{
$openid= $request['openid'];
......
......@@ -190,7 +190,48 @@ class RAM_REST_Posts_Controller extends WP_REST_Controller{
),
// Register our schema callback.
'schema' => array( $this, 'get_public_item_schema' ),
) );
) );
register_rest_route( $this->namespace, '/' . $this->resource_name.'/about', array(
// Here we register the readable endpoint for collections.
array(
'methods' => 'GET',
'callback' => array( $this, 'getPostAbout' ),
'permission_callback' => array( $this, 'get_item_permissions_check' )
),
// Register our schema callback.
'schema' => array( $this, 'get_public_item_schema' ),
) );
}
function getPostAbout($request)
{
$aboutId= get_option("wf_about");
if(empty($aboutId))
{
return new WP_Error( 'error', '未设置关于页面' , array( 'status' => "404" ) );
}
else{
$posts =getPosts($aboutId);
if(count($posts)>0)
{
$post=$posts[0];
$response = rest_ensure_response($post);
return $response;
}
else{
return new WP_Error( 'error', '关于页面设置有错误' , array( 'status' => "404" ) );
}
}
}
function getallpraise ($request)
......@@ -421,9 +462,9 @@ class RAM_REST_Posts_Controller extends WP_REST_Controller{
$_data['post_thumbnail_image_624']=$images['post_thumbnail_image_624'];
$_data['post_frist_image']=$images['post_frist_image'];
$_data['post_medium_image']=$images['post_medium_image'];
$_data['post_large_image']=$images['post_large_image'];
$_data['post_full_image']=$images['post_full_image'];
$_data['post_all_images']=$images['post_all_images'];
$_data['post_large_image']=$images['post_large_image'];
$_data['post_full_image']=$images['post_full_image'];
$_data['post_all_images']=$images['post_all_images'];
$posts[] = $_data;
......@@ -528,6 +569,7 @@ class RAM_REST_Posts_Controller extends WP_REST_Controller{
return $response;
}
function getPostSwipe($request) {
global $wpdb;
......@@ -535,41 +577,7 @@ class RAM_REST_Posts_Controller extends WP_REST_Controller{
$posts =array();
if(!empty($postSwipeIDs))
{
$sql="SELECT * from ".$wpdb->posts." where id in(".$postSwipeIDs.") ORDER BY find_in_set(id,'".$postSwipeIDs."')";
$_posts = $wpdb->get_results($sql);
foreach ($_posts as $post) {
$post_id = (int) $post->ID;
$post_title = stripslashes($post->post_title);
$post_date =$post->post_date;
$post_permalink = get_permalink($post->ID);
$_data["id"] =$post_id;
$_data["post_title"] =$post_title;
$_data["post_date"] =$post_date;
$_data["post_permalink"] =$post_permalink;
$_data['type']="detailpage";
$pageviews = (int) get_post_meta( $post_id, 'wl_pageviews',true);
$_data['pageviews'] = $pageviews;
$comment_total = $wpdb->get_var("SELECT COUNT(1) FROM ".$wpdb->comments." where comment_approved = '1' and comment_post_ID=".$post_id);
$_data['comment_total']= $comment_total;
$images =getPostImages($post->post_content,$post_id);
$_data['post_thumbnail_image']=$images['post_thumbnail_image'];
$_data['content_first_image']=$images['content_first_image'];
$_data['post_medium_image_300']=$images['post_medium_image_300'];
$_data['post_thumbnail_image_624']=$images['post_thumbnail_image_624'];
$_data['post_frist_image']=$images['post_frist_image'];
$_data['post_medium_image']=$images['post_medium_image'];
$_data['post_large_image']=$images['post_large_image'];
$_data['post_full_image']=$images['post_full_image'];
$_data['post_all_images']=$images['post_all_images'];
$posts[] = $_data;
}
$posts=getPosts($postSwipeIDs);
$result["code"]="success";
$result["message"]= "获取轮播图成功";
$result["status"]="200";
......
......@@ -3,6 +3,30 @@
function custom_fields_rest_prepare_category( $data, $item, $request ) {
$category_thumbnail_image='';
$temp='';
$openid= $request["openid"];
$subscription =getSubscription($openid);
$id =(string)$item->term_id;
if(empty($subscription))
{
$data->data['subimg'] ="subscription.png";
$data->data['subflag'] ="0";
}
else
{
if(array_search($id,$subscription ))
{
$data->data['subimg'] ="subscription-on.png";
$data->data['subflag'] ="1";
}
else
{
$data->data['subimg'] ="subscription.png";
$data->data['subflag'] ="0";
}
}
if($temp=get_term_meta($item->term_id,'catcover',true))
{
$category_thumbnail_image=$temp;
......@@ -17,6 +41,32 @@ function custom_fields_rest_prepare_category( $data, $item, $request ) {
return $data;
}
function getSubscription($openid)
{
global $wpdb;
$user_id =0;
$user = get_user_by('login', $openid);
$subscription= array();
if($user)
{
$user_id = $user->ID;
$usermeta = get_user_meta($user_id);
if (!empty($usermeta))
{
if(!empty($usermeta['wl_sub']))
{
$subscription=$usermeta['wl_sub'];
}
}
}
return $subscription;
}
/********* 给分类添加微信小程序封面 *********/
......
......@@ -603,4 +603,59 @@ function get_content_gallery($content,$flag){
return $vcontent;
}
\ No newline at end of file
}
function getPosts($ids)
{
global $wpdb;
$sql="SELECT * from ".$wpdb->posts." where id in(".$ids.") ORDER BY find_in_set(id,'".$ids."')";
$_posts = $wpdb->get_results($sql);
$posts =array();
if(!empty($_posts))
{
foreach ($_posts as $post) {
$post_id = (int) $post->ID;
$post_title = stripslashes($post->post_title);
$post_content= nl2br($post->post_content);
$post_date =$post->post_date;
$post_permalink = get_permalink($post->ID);
$_data["id"] =$post_id;
$_data["post_title"] =$post_title;
$_data["post_content"] =$post_content;
$_data["post_date"] =$post_date;
$_data["post_permalink"] =$post_permalink;
$_data['type']="detailpage";
$enterpriseMinapp=get_option('wf_enterprise_minapp');
$enterpriseMinapp=empty($enterpriseMinapp)?'0':$enterpriseMinapp;
$_data['enterpriseMinapp']=$enterpriseMinapp;
$praiseWord=get_option('wf_praise_word');
$praiseWord=empty($praiseWord)?'鼓励':$praiseWord;
$_data['praiseWord']=$praiseWord;
$pageviews = (int) get_post_meta( $post_id, 'wl_pageviews',true);
$_data['pageviews'] = $pageviews;
$comment_total = $wpdb->get_var("SELECT COUNT(1) FROM ".$wpdb->comments." where comment_approved = '1' and comment_post_ID=".$post_id);
$_data['comment_total']= $comment_total;
$images =getPostImages($post->post_content,$post_id);
$_data['post_thumbnail_image']=$images['post_thumbnail_image'];
$_data['content_first_image']=$images['content_first_image'];
$_data['post_medium_image_300']=$images['post_medium_image_300'];
$_data['post_thumbnail_image_624']=$images['post_thumbnail_image_624'];
$_data['post_frist_image']=$images['post_frist_image'];
$_data['post_medium_image']=$images['post_medium_image'];
$_data['post_large_image']=$images['post_large_image'];
$_data['post_full_image']=$images['post_full_image'];
$_data['post_all_images']=$images['post_all_images'];
$posts[] = $_data;
}
}
return $posts;
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册