Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ijianbo
rest Api To Miniprogram
提交
ef425eef
rest Api To Miniprogram
项目概览
ijianbo
/
rest Api To Miniprogram
通知
22
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
rest Api To Miniprogram
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ef425eef
编写于
2月 28, 2024
作者:
X
xjb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加“发现”api
上级
7920bc99
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
82 addition
and
1 deletion
+82
-1
includes/api/ram-rest-posts-controller.php
includes/api/ram-rest-posts-controller.php
+81
-0
rest-api-to-miniprogram.php
rest-api-to-miniprogram.php
+1
-1
未找到文件。
includes/api/ram-rest-posts-controller.php
浏览文件 @
ef425eef
...
...
@@ -203,6 +203,82 @@ 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
.
'/rand'
,
array
(
// Here we register the readable endpoint for collections.
array
(
'methods'
=>
'GET'
,
'callback'
=>
array
(
$this
,
'get_posts_rand'
),
'permission_callback'
=>
array
(
$this
,
'get_item_permissions_check'
)
),
// Register our schema callback.
'schema'
=>
array
(
$this
,
'get_public_item_schema'
),
)
);
}
public
function
get_posts_rand
(
$request
){
$categoriesId
=
get_option
(
'wf_display_categories'
);
global
$wpdb
;
if
(
empty
(
$categoriesId
))
{
$args
=
array
(
'numberposts'
=>
30
,
'orderby'
=>
'rand'
,
);
}
else
{
$args
=
array
(
'numberposts'
=>
30
,
'orderby'
=>
'rand'
,
'category'
=>
$categoriesId
);
}
$postsRand
=
get_posts
(
$args
);
$posts
=
array
();
foreach
(
$postsRand
as
$post
)
{
$post_id
=
(
int
)
$post
->
ID
;
$post_title
=
stripslashes
(
$post
->
post_title
);
$comment_total
=
(
int
)
$post
->
comment_total
;
$post_date
=
$post
->
post_date
;
$post_permalink
=
get_permalink
(
$post
->
ID
);
$_data
[
"post_id"
]
=
$post_id
;
$_data
[
"id"
]
=
$post_id
;
$_data
[
"post_title"
]
=
$post_title
;
$_data
[
"comment_total"
]
=
$comment_total
;
$_data
[
"post_date"
]
=
$post_date
;
$_data
[
"post_permalink"
]
=
$post_permalink
;
$pageviews
=
(
int
)
get_post_meta
(
$post_id
,
'wl_pageviews'
,
true
);
$_data
[
'pageviews'
]
=
$pageviews
;
$like_count
=
$wpdb
->
get_var
(
"SELECT COUNT(1) FROM "
.
$wpdb
->
postmeta
.
" where meta_value='like' and post_id="
.
$post_id
);
$_data
[
'like_count'
]
=
$like_count
;
$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
;
}
$response
=
rest_ensure_response
(
$posts
);
return
$response
;
}
function
getPostAbout
(
$request
)
...
...
@@ -346,6 +422,7 @@ class RAM_REST_Posts_Controller extends WP_REST_Controller{
$post_date
=
$post
->
post_date
;
$post_permalink
=
get_permalink
(
$post
->
ID
);
$_data
[
"post_id"
]
=
$post_id
;
$_data
[
"id"
]
=
$post_id
;
$_data
[
"post_title"
]
=
$post_title
;
//$_data["pageviews"] =$pageviews;
$_data
[
"post_date"
]
=
$post_date
;
...
...
@@ -413,6 +490,7 @@ class RAM_REST_Posts_Controller extends WP_REST_Controller{
$post_date
=
$post
->
post_date
;
$post_permalink
=
get_permalink
(
$post
->
ID
);
$_data
[
"post_id"
]
=
$post_id
;
$_data
[
"id"
]
=
$post_id
;
$_data
[
"post_title"
]
=
$post_title
;
$_data
[
"pageviews"
]
=
$pageviews
;
$_data
[
"post_date"
]
=
$post_date
;
...
...
@@ -480,6 +558,7 @@ class RAM_REST_Posts_Controller extends WP_REST_Controller{
$post_date
=
$post
->
post_date
;
$post_permalink
=
get_permalink
(
$post
->
ID
);
$_data
[
"post_id"
]
=
$post_id
;
$_data
[
"id"
]
=
$post_id
;
$_data
[
"post_title"
]
=
$post_title
;
$_data
[
"like_count"
]
=
$like_total
;
$_data
[
"post_date"
]
=
$post_date
;
...
...
@@ -531,6 +610,7 @@ class RAM_REST_Posts_Controller extends WP_REST_Controller{
$post_date
=
$post
->
post_date
;
$post_permalink
=
get_permalink
(
$post
->
ID
);
$_data
[
"post_id"
]
=
$post_id
;
$_data
[
"id"
]
=
$post_id
;
$_data
[
"post_title"
]
=
$post_title
;
$_data
[
"comment_total"
]
=
$comment_total
;
$_data
[
"post_date"
]
=
$post_date
;
...
...
@@ -597,6 +677,7 @@ class RAM_REST_Posts_Controller extends WP_REST_Controller{
$post_date
=
$post
->
post_date
;
$post_permalink
=
get_permalink
(
$post
->
ID
);
$_data
[
"post_id"
]
=
$post_id
;
$_data
[
"id"
]
=
$post_id
;
$_data
[
"post_title"
]
=
$post_title
;
$_data
[
"comment_total"
]
=
$comment_total
;
$_data
[
"post_date"
]
=
$post_date
;
...
...
rest-api-to-miniprogram.php
浏览文件 @
ef425eef
...
...
@@ -3,7 +3,7 @@
Plugin Name: REST API TO MiniProgram 微慕小程序
Plugin URI: https://www.minapper.com
Description: 为微慕小程序提供定制化WordPress REST API json 输出
Version: 4.6.
8.2
Version: 4.6.
9
Author: jianbo
Author URI: https://www.minapper.com
License: GPL v3
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录