如何将帖子 ID 添加到 JSON URL?

编程入门 行业动态 更新时间:2024-10-28 08:24:56
本文介绍了如何将帖子 ID 添加到 JSON URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我不熟悉 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 02:10:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1076411.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   帖子   ID   JSON   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!