如何将帖子 ID 添加到 JSON URL? [英] How to add post ID to JSON URL?

查看:29
本文介绍了如何将帖子 ID 添加到 JSON URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不熟悉 PHP 语法.现在我将 JSON 插件添加到我的 wordpress 网站并激活它.

I am not familiar with PHP Syntax. Now i added JSON Plugin to my wordpress website and activate it.

当我打开 url 到 get_recent_post 时,没问题.JSON 数据正在显示.

When i open url to get_recent_post , it's fine. JSON data are showing.

但是当我打开 get_post 时,它只显示

But when i open get_post , it's only showing

{"status":"error","error":"Include 'id' or 'slug' var in your request."}

所以我不知道如何将帖子 ID 添加到该 URL.

So i don't know how to add post id to that URL.

这是图片.另一个 get_page 、gate_date_posts 等...链接同样显示错误.

here is the pic. Another get_page , gate_date_posts, etc... links are same showing error.

我该怎么做?

推荐答案

要显示帖子的 ID,只需在 WordPress 循环中使用以下 PHP 代码:

To display a post's ID, simply use the following PHP code within the WordPress loop:

<?php the_ID(); ?>

要返回 ID,请在 WordPress 循环中使用以下 PHP 代码:

To return the ID, use the following PHP code within the WordPress loop:

<?php get_the_ID; ?>

要在 WordPress 循环之外获取帖子的 id,请使用以下 PHP 代码:

To get a post's id outside of the WordPress loop use the following PHP code:

<?php global $post; $post->ID ?>

希望能帮到你.

这篇关于如何将帖子 ID 添加到 JSON URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆