shortcode怎么用
Have you ever seen showcases like 25 best XYZ sites to follow? Usually these tutorials have the site name, site screenshot, a small description, and the list of recent posts. The main issue with those posts are the list of recent posts which gets outdated overtime because most authors manually create those links at the time of writing. That post is really outdated as soon as any one of those other sites publish a new post. Well in this article, we will show you how to embed an external RSS feed in WordPress posts via shortcode, so you can keep your list posts relevant.
您是否见过像25个最佳XYZ网站这样的展示柜? 通常,这些教程包含站点名称,站点屏幕截图,简短描述以及最近发布的列表。 这些帖子的主要问题是最近的帖子列表,这些列表超时了,因为大多数作者在撰写本文时都手动创建了这些链接。 只要其他任何一个站点发布新帖子,该帖子实际上就已经过时了。 在本文中,我们将向您展示如何通过简码将外部RSS feed嵌入WordPress帖子中,以便使列表帖子保持相关性。
First thing you need to do is open your theme’s functions.php file and paste the following code:
您需要做的第一件事是打开主题的functions.php文件,并粘贴以下代码:
//This file is needed to be able to use the wp_rss() function.
include_once(ABSPATH.WPINC.'/rss.php');
function readRss($atts) {
extract(shortcode_atts(array(
"feed" => 'http://',
"num" => '1',
), $atts));
return wp_rss($feed, $num);
}
add_shortcode('rss', 'readRss');
Now all you have to do is use this shortcode when writing a post:
现在您所要做的就是在编写帖子时使用以下短代码:
[rss feed="http://feeds.feedburner.com/wpbeginner" num="5"]
Make sure you change the feed URL in the shortcode to what you want. You can also adjust the number to your liking.
确保将简码中的供稿网址更改为所需的网址。 您也可以根据自己的喜好调整数字。
Source: Smashing Magazine
资料来源:《 粉碎杂志》
shortcode怎么用