wordpress 自定义_自定义WordPress嵌入内容

本文介绍了如何在WordPress中创建一个名为'Status Update'的简单插件,该插件注册自定义帖子类型并自定义oEmbed输出,显示用户的姓名和头像。通过使用oEmbed的发现、JSON响应和过滤器,可以实现自定义嵌入标题和节选,以及添加额外内容和样式。
摘要由CSDN通过智能技术生成

wordpress 自定义

WordPress makes it very easy to embed content. For example, you can grab a YouTube URL, drop it into the post editor, and automatically see a video embedded in your post. This is all powered by oEmbed, an open standard for how a page should provide embed code data.

WordPress使嵌入内容变得非常容易。 例如,您可以获取YouTube URL,将其放入帖子编辑器中,然后自动查看帖子中嵌入的视频。 这全部由oEmbed提供支持, oEmbed是页面应如何提供嵌入代码数据的开放标准。

WordPress relies on this standard in order to fetch and display a provided URL. While WordPress has long been able to consume oEmbed providers like YouTube, with the inclusion of the WP-API in WordPress 4.4, WordPress can now function as an oEmbed provider. This means other sites can embed your WordPress content on their sites as easily as you can currently embed videos as mentioned in the example above.

WordPress依靠此标准来获取和显示提供的URL。 尽管WordPress长期以来一直可以使用YouTube之类的嵌入式服务提供商,但WordPress 4.4中包含了WP-API ,WordPress现在可以用作嵌入式服务提供商。 这意味着其他站点可以像上面示例中提到的那样当前轻松地将视频嵌入WordPress内容。

The new oEmbed provider functionality leverages the WP-API to return JSON or XML structured embed data to oEmbed consumers, giving them the information they need to embed the page on their own. Like everything in WordPress, the oEmbed provider functionality is easily modifiable with actions and filters. Let’s take a look at how we can use these hooks to embed a custom post type.

新的oEmbed提供程序功能利用WP-API将JSON或XML结构的嵌入数据返回给oEmbed消费者,从而为他们提供了自己嵌入页面所需的信息。 像WordPress中的所有内容一样,oEmbed提供程序功能可以通过actionfilter轻松修改。 让我们看一下如何使用这些挂钩来嵌入自定义帖子类型。

oEmbed WordPress

我们将要建设的 (What We’ll Be Building)

We’re going to be building a simple plugin, ‘Status Update’, which registers a custom post type (CPT), status-update. This CPT simply removes the title input in the post editor, making it function like a Facebook or Twitter status update. We’ll customize the oEmbed output of this post to show the user’s name and avatar. You can see the final product in this GitHub repo.

我们将要构建一个简单的插件“状态更新”,该插件注册自定义帖子类型(CPT),即status-update 。 该CPT只需删除帖子编辑器中的标题输入,使其功能类似于Facebook或Twitter状态更新。 我们将自定义此帖子的oEmbed输出,以显示用户的姓名和头像。 您可以在此GitHub存储库中查看最终产品。

设置插件 (Setting up the Plugin)

Go to your plugins folder in wp-content and create a folder named sp-status-update. In that directory, create a file named sp-status-update.php. This is where we’ll be creating the plugin’s main class. Add the plugin header to the top of the file:

转到wp-content plugins文件夹,然后创建一个名为sp-status-update的文件夹。 在该目录中,创建一个名为sp-status-update.php的文件。 这是我们将创建插件的主类的地方。 将插件标头添加到文件顶部:

/**
 * Plugin Name: Status Update
 * Plugin URI:  https://github.com/mAAdhaTTah/sitepoint-status-update
 * Description: Post your own Facebook-like status updates
 * Version:     1.0.0
 * Author:      James DiGioia for SitePoint
 * Author URI:  http://jamesdigioia.com
 * Text Domain: wp-status-update
 * Languages:   /languages
 */

We’ll then set up the main plugin singleton on which we’ll build our plugin:

然后,我们将建立主插件单例,以在其上构建插件:

class SP_Status_Update {

    /**
     * Plugin instance.
     *
     * @var static
     */
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值