自定义页面与插件 Slug [英] Custom Page vs Plugin Slug

查看:28
本文介绍了自定义页面与插件 Slug的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将来自第三方 API 的信息集成到 wordpress 站点中.我需要做的是创建一个动态页面",在其中显示来自 API 的特定记录的详细信息.由于有 1000 条记录,我不想在 wordpress 中为每个记录详细信息视图创建一个单独的页面.

I'm currently integrating information from a third party API into a wordpress site. What i need to do is create a "dynamic page" where it displays the details of a specific record from the API. Since there are 1000's of records i dont want to create a seperate page in wordpress for every record detail view.

我环顾四周,似乎有两个主要解决方案(我已经放弃了自定义帖子类型选项,因为我认为它不符合我的需求,但我愿意重新评估).首先是在wordpress页面管理中创建一个页面,然后为该页面设置一个调用API方法的自定义模板,然后只构建模板.第二个是以某种方式使用我创建的插件,为我使用的 URL 注册一个钩子,然后让插件处理显示(我还不确定我是怎么做的).

I've been looking around and it seems there are two main solutions (i've discarded the custom post type option as i dont think it fits my needs, but im open to re-evaluate). The first is to create a page in the wordpress pages admin, then setup a custom template for that page which calls the API methods, then just builds the template. The second is to somehow use the plugin i created, to register a hook for the URL im using, then have the plugin handle the display (not sure how i go about that yet).

我想知道这里的人认为什么是最好的方法.前提条件是:

I'm wondering what people here think is the best approach. The prerequisites are:

  1. 为了能够处理 URL 来检索记录的 ID显示(必须支持标准 URL 参数以及自定义 slug).
  2. 拥有自定义模板(能够调用get_sidebar() 函数作为它的小部件)
  3. 在某个时候,我将添加一个管理面板,以向每个记录详细信息显示添加其他内容,例如外部 CMS 不支持的相关图像.

任何建议或最佳方向的观点将不胜感激,谢谢

Any advice or a point in the best direction would be appreciated, thanks

推荐答案

这周我在为我正在处理的 WordPress 网站编写自定义 API (REST + JSON) 时遇到了这个问题.我的解决方案是使用页面模板并将其用作 API 的入口点.那时我遇到了 https://stackoverflow.com/a/4975004/1386140.但是,一个问题是它需要用户(站点管理员)为页面添加标题以匹配插件检查的参数

I ran into this the week while writing a custom API (REST + JSON) for a WordPress site I was working on. My solution was to use a page-template and use that as the entry point for the API. That's when I came across https://stackoverflow.com/a/4975004/1386140. The one catch, though, is that it would require the user (admin of the site) to title the page to match the parameter that the plugin checks against

$wp->query_vars["pagename"] == 'YOUR_PAGE_NAME'

就我而言,这已经绰绰有余,尤其是因为我们重定向了不相关的流量.这允许在 URL 中使用额外的查询参数,但对 slug 并不友好.因为它仍然会作为典型的页面方法被调用,比如 get_sidebar() 仍然可以工作.

For my purpose, this was more than sufficient, especially since we redirected irrelevant traffic. This allows additional query parameters in the URL, though doesn't play friendly with slugs. Since it will still be called as a typical page methods like get_sidebar() would still work.

为了让它与 slugs 一起工作,我会看看这篇文章(https://stackoverflow.com/a/2487407/1386140 ) 以朝着正确的方向开始(看起来合法,但我之前从未使用过自定义重写规则和插件).

To get it to work with slugs, I would look at this post ( https://stackoverflow.com/a/2487407/1386140 ) to get started in the right direction (looks legit, but I haven't worked with custom rewrite rules and plugins before).

这篇关于自定义页面与插件 Slug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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