wordpress本地开发_WordPress提要开发人员指南

2023-12-27 14:40

本文主要是介绍wordpress本地开发_WordPress提要开发人员指南,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

wordpress本地开发

A feed is a data format used for providing users with frequently updated content. Feed readers are used to read a feed, thereby allowing users to subscribe to it. Making a collection of feeds accessible in one spot is known as aggregation, which is performed by a feed aggregator.

提要是一种数据格式,用于为用户提供频繁更新的内容。 提要阅读器用于阅读提要,从而允许用户订阅它。 使一个集合的提要可以在一个位置访问是众所周知的聚合,这是由一个提要聚合器执行的。

WordPress Feeds

In this tutorial I’ll show you the different kinds of feed formats provided by WordPress and how to access them, with a focus on customizing them programmatically.

在本教程中,我将向您展示WordPress提供的各种提要格式以及如何访问它们,重点是以编程方式自定义它们。

WordPress支持的提要格式 (Feed Formats Supported by WordPress)

WordPress supports four popular feed formats: RDF, RSS 0.92, RSS 2.0 and Atom. RSS 2.0 is the most popular feed format and is supported by almost every feed reader.

WordPress支持四种流行的提要格式:RDF,RSS 0.92,RSS 2.0和Atom。 RSS 2.0是最流行的提要格式,几乎每个提要阅读器都支持它。

The URL paths for these feeds are:

这些提要的URL路径是:


http://example.com/?feed=rss
http://example.com/?feed=rss2
http://example.com/?feed=rdf
http://example.com/?feed=atom

You don’t have to hardcode them into your themes or plugins, you can just use the following functions to retrieve the URLs of the various feed formats:

您不必将它们硬编码到主题或插件中,只需使用以下功能即可检索各种提要格式的URL:

<?php 
bloginfo('rdf_url'); 
bloginfo('rss_url'); 
bloginfo('rss2_url'); 
bloginfo('atom_url');
?>

These URLs retrieve the latest ‘posts’ of the site.

这些URL检索网站的最新“帖子”。

WordPress最近评论提要 (WordPress Recent Comments Feed)

The above paths provide the latest posts of the site. To find recent comments we need to use the comments specific feed path:

以上路径提供了该网站的最新帖子。 要查找最近的评论,我们需要使用评论特定的供稿路径:

http://example.com/?feed=comments-rss2

If you don’t want to hardcode it, you can use this function to retrieve the comments feed:

如果您不想对其进行硬编码,则可以使用此函数来检索注释提要:

<?php
bloginfo('comments_rss2_url');

WordPress also provides a feed for comments of a single post. To find the recent comments of a specific post the feed path is:

WordPress还提供了供稿,用于评论单个帖子。 要查找特定帖子的最新评论,提要路径为:

http://example.com/?p=id&feed=rss2

Again, if you don’t want to hardcode it, you can use this function to retrieve it:

同样,如果您不想对其进行硬编码,则可以使用以下函数进行检索:

<?php
post_comments_feed_link('link_text', 'post_id', 'rss2' );

WordPress分类供稿 (WordPress Category Feed)

WordPress provides a feed for every category. The feed path for a single category or multiple categories is:

WordPress提供了每个类别的供稿。 单个类别或多个类别的提要路径为:

http://www.example.com/?cat=id1,id2&feed=rss2

You can use this function to retrieve the feed URL of a single category or multiple categories by using the following:

您可以使用此功能通过以下方式检索单个类别或多个类别的提要URL:

<?php
get_category_feed_link('id1', 'rss2');

Similarly, you can also get the feed URL of a tag or multiple tags too.

同样,您也可以获取一个标签或多个标签的Feed URL。

WordPress作者提要 (WordPress Author Feed)

WordPress also provides a feed for the recent posts of an author. This is useful if a user wants to follow a particular author via a feed.

WordPress还为作者的最新帖子提供了提要。 如果用户想通过提要关注特定作者,这将很有用。

The URL path of an author’s feed can be constructed using the below code:

可以使用以下代码构造作者提要的URL路径:

<?php 
echo '<a href="' . get_author_link(0, $authordata->ID, $authordata->user_nicename) . 'feed/">' . the_author($idmode, false) . '</a>';

Note: WordPress doesn’t provide any built-in functions to retrieve the URL of an author feed.

注意:WordPress没有提供任何内置功能来检索作者供稿的URL。

WordPress搜索供稿 (WordPress Search Feed)

WordPress can also retrieve a feed for a search term. Here’s the feed URL path for a search term:

WordPress还可以检索搜索词的提要。 以下是搜索字词的供稿网址路径:

http://example.com/?s=sitepoint&feed=rss2

查看提要请求 (Check Feed Request)

In your theme or plugin, you can check if a request is a feed request or not by using the below code:

在主题或插件中,可以使用以下代码检查请求是否为供稿请求:

<?php
if(is_feed())
{
echo "Feed Request";
}

Here we are using the is_feed() function to check if the current request is a feed request or not. If yes, then it returns true.

在这里,我们使用is_feed()函数检查当前请求是否为feed请求。 如果是,则返回true。

WordPress internally uses a built in feed template to display feeds. Using the do_feed action we can define our own feed templates.

WordPress内部使用内置的提要模板来显示提要。 使用do_feed操作,我们可以定义自己的提要模板。

删除提要 (Remove Feeds)

If you don’t want to provide feeds on your site, then you can use the code below to disable all of them:

如果您不想在您的网站上提供供稿,则可以使用以下代码禁用所有供稿:

<?php
function disable_feed() 
{
wp_die(__("Feed Disabled"));
}
add_action('do_feed',      'disable_feed', 1);
add_action('do_feed_rdf',  'disable_feed', 1);
add_action('do_feed_rss',  'disable_feed', 1);
add_action('do_feed_rss2', 'disable_feed', 1);
add_action('do_feed_atom', 'disable_feed', 1);

过滤Feed内容 (Filtering Feed Content)

To filter the description of a post in a feed only we can use the_content_feed filter. Here is an example on how to use it:

要仅过滤Feed中帖子的描述,我们可以使用the_content_feed过滤器。 这是有关如何使用它的示例:

function feed_word_count($content)
{
$content .= 'Total '.str_word_count($content).' words';
return $content;
}
add_filter("the_content_feed", "feed_word_count");

In WordPress 3.0 onwards, there is a theme support feature to add feed URLs to the head tag. If you’re a WordPress theme developer, then add this line of code to your theme’s function.php file to enable this feature.

在WordPress 3.0及更高版本中,提供了主题支持功能,可将供稿URL添加到head标签。 如果您是WordPress主题开发人员,请将此代码行添加到主题的function.php文件中以启用此功能。

add_theme_support( 'automatic-feed-links' );

将WordPress提要重定向到FeedBurner提要 (Redirecting WordPress Feeds to FeedBurner Feeds)

Many site administrators prefer to provide their feeds using FeedBurner (or other third party services). This lets them track their feeds and number of subscribers.

许多站点管理员更喜欢使用FeedBurner (或其他第三方服务)提供其提要。 这样一来,他们就可以跟踪自己的供稿和订阅者人数。

The dirty way to do this is by adding the below code to .htaccess file

这样做的肮脏方法是将以下代码添加到.htaccess文件中

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} !FeedBurner    [NC]
RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/name [R=302,NC,L]
</IfModule>

This code redirects requests to the latest posts feed to FeedBurner.

此代码将请求重定向到FeedBurner的最新帖子提要。

If you’re hesitant to touch your .htaccess file, then you can use FeedBurner Plugin to do the same thing.

如果您不愿意触摸.htaccess文件,则可以使用FeedBurner插件执行相同的操作。

更多动作和过滤器 (More Actions and Filters)

WordPress provides many more actions and filters to customize our feeds. We’ve only covered some of the most important and useful ones.

WordPress提供了更多的操作和过滤器来定制我们的提要。 我们仅介绍了一些最重要和最有用的内容。

You can find many more feed related actions at WordPress Action Reference and filters at WordPress Filter Reference.

您可以在WordPress操作参考中找到更多与提要相关的操作,并在WordPress过滤器参考中找到过滤器 。

结论 (Conclusion)

Many WordPress users prefer feed subscriptions rather than email or social subscriptions. As feed aggregators are now available for all platforms it’s a good idea to provide users an option to subscribe via feeds, with RSS 2.0 being the preferred format. You should also display an author feed and a comments feed if you have commenting enabled, not just recent posts feed.

许多WordPress用户更喜欢订阅订阅,而不是电子邮件或社交订阅。 由于feed聚合器现在可用于所有平台,因此最好为用户提供通过feed订阅的选项,其中RSS 2.0是首选格式。 如果您已启用评论功能,那么您还应该显示作者信息源和评论信息源,而不仅仅是最近的帖子信息源。

Let me know your experience with WordPress feeds below.

在下面让我知道您对WordPress feed的体验。

翻译自: https://www.sitepoint.com/developers-guide-to-feeds-in-wordpress/

wordpress本地开发

这篇关于wordpress本地开发_WordPress提要开发人员指南的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/543463

相关文章

Android开发中gradle下载缓慢的问题级解决方法

《Android开发中gradle下载缓慢的问题级解决方法》本文介绍了解决Android开发中Gradle下载缓慢问题的几种方法,本文给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、网络环境优化二、Gradle版本与配置优化三、其他优化措施针对android开发中Gradle下载缓慢的问

Nginx实现动态封禁IP的步骤指南

《Nginx实现动态封禁IP的步骤指南》在日常的生产环境中,网站可能会遭遇恶意请求、DDoS攻击或其他有害的访问行为,为了应对这些情况,动态封禁IP是一项十分重要的安全策略,本篇博客将介绍如何通过NG... 目录1、简述2、实现方式3、使用 fail2ban 动态封禁3.1 安装 fail2ban3.2 配

使用Go语言开发一个命令行文件管理工具

《使用Go语言开发一个命令行文件管理工具》这篇文章主要为大家详细介绍了如何使用Go语言开发一款命令行文件管理工具,支持批量重命名,删除,创建,移动文件,需要的小伙伴可以了解下... 目录一、工具功能一览二、核心代码解析1. 主程序结构2. 批量重命名3. 批量删除4. 创建文件/目录5. 批量移动三、如何安

Java中String字符串使用避坑指南

《Java中String字符串使用避坑指南》Java中的String字符串是我们日常编程中用得最多的类之一,看似简单的String使用,却隐藏着不少“坑”,如果不注意,可能会导致性能问题、意外的错误容... 目录8个避坑点如下:1. 字符串的不可变性:每次修改都创建新对象2. 使用 == 比较字符串,陷阱满

python使用fastapi实现多语言国际化的操作指南

《python使用fastapi实现多语言国际化的操作指南》本文介绍了使用Python和FastAPI实现多语言国际化的操作指南,包括多语言架构技术栈、翻译管理、前端本地化、语言切换机制以及常见陷阱和... 目录多语言国际化实现指南项目多语言架构技术栈目录结构翻译工作流1. 翻译数据存储2. 翻译生成脚本

Android 悬浮窗开发示例((动态权限请求 | 前台服务和通知 | 悬浮窗创建 )

《Android悬浮窗开发示例((动态权限请求|前台服务和通知|悬浮窗创建)》本文介绍了Android悬浮窗的实现效果,包括动态权限请求、前台服务和通知的使用,悬浮窗权限需要动态申请并引导... 目录一、悬浮窗 动态权限请求1、动态请求权限2、悬浮窗权限说明3、检查动态权限4、申请动态权限5、权限设置完毕后

使用 sql-research-assistant进行 SQL 数据库研究的实战指南(代码实现演示)

《使用sql-research-assistant进行SQL数据库研究的实战指南(代码实现演示)》本文介绍了sql-research-assistant工具,该工具基于LangChain框架,集... 目录技术背景介绍核心原理解析代码实现演示安装和配置项目集成LangSmith 配置(可选)启动服务应用场景

0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeek R1模型的操作流程

《0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeekR1模型的操作流程》DeepSeekR1模型凭借其强大的自然语言处理能力,在未来具有广阔的应用前景,有望在多个领域发... 目录0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeek R1模型,3步搞定一个应

一文教你使用Python实现本地分页

《一文教你使用Python实现本地分页》这篇文章主要为大家详细介绍了Python如何实现本地分页的算法,主要针对二级数据结构,文中的示例代码简洁易懂,有需要的小伙伴可以了解下... 在项目开发的过程中,遇到分页的第一页就展示大量的数据,导致前端列表加载展示的速度慢,所以需要在本地加入分页处理,把所有数据先放

本地搭建DeepSeek-R1、WebUI的完整过程及访问

《本地搭建DeepSeek-R1、WebUI的完整过程及访问》:本文主要介绍本地搭建DeepSeek-R1、WebUI的完整过程及访问的相关资料,DeepSeek-R1是一个开源的人工智能平台,主... 目录背景       搭建准备基础概念搭建过程访问对话测试总结背景       最近几年,人工智能技术