[英]How to create a javascript widget to load recent posts from my wordpress site and display in other sites?
I have a WordPress site.我有一个 WordPress 网站。 I want to allow others to place a web widget in their website which grabs recent posts from my site and display title with a link to its page for each of my recent posts.
我想允许他人放置网络小工具在他们的网站,抓住从我的网站和显示标题的帖子最近一个链接到其页面每个我最近发表的文章。 I know that this is possible through using iframe.
我知道,这是有可能通过使用iframe中。 But this has no positive effect on my website SEO.
但这对我的网站 SEO 没有积极影响。 I found a solution here to use JavaScript for similar purpose.
我发现了一个解决方案在这里使用JavaScript进行类似的目的。 But it used Python and JSON to load HTML from the original site in the main() function.
但是,使用Python和JSON来从main()函数原有的网站加载HTML。 I am not familiar with JSON and Python.
我不熟悉 JSON 和 Python。 Is there any solution that I can return my recent posts using PHP and put it in the main function?
是否有任何解决方案,我可以使用PHP回到我的最新文章,并把它的主要功能?
I use SimplePie to get RSS feeds.我使用SimplePie来获取 RSS 提要。 This is the function I use.
这是我使用的功能。
function start_rss(){
$urls = array(
0 => 'http://ogmarketreport.com',
1 => 'http://petroriveroil.com/feed/'
);
$numberOfPosts = 10;
foreach ($urls as $key => $value) {
$url = $value;
$feed = new SimplePie();
$feed->set_cache_location($_SERVER['DOCUMENT_ROOT'] . '/cache/');
$feed->set_feed_url($url);
$feed->set_stupidly_fast(true);
$feed->init();
$feed->handle_content_type();
$blog_title = $feed->get_title();
$blog_title_url = '<div class="row" style="width: 100%; display: block;"><h2><a href="<?php $feed->get_permalink(); ?>" target="_blank"><?php $title; ?></a></h2></div>';
$blog_desc = $feed->get_description();
$html = "";
$x = $feed->get_items(0, $numberOfPosts);
$html .= '<div class="container" style="width: 100%; display: block;"><h2><a target="_blank" href="' .$feed->get_permalink() . '">' . $feed->get_title() . '</a></h2></div>';
if (count($x) == 0 ) {
$html .= '<article class="rss col-md-12">';
$html .= '<p class="danger">No Recent Posts.</p>';
$html .= '</article>';
} else {
foreach ($x as $item) {
$html .= '<article class="rss col-md-12">';
$html .= '<h4 class="title">';
$html .= '<a href="' .$item->get_permalink() . '">' .$item->get_title() . '</a>' ;
$html .= '</h4>';
$html .= '<p>';
$html .= $item->get_description();
$html .= '</p>';
$html .= '<p><small>';
$html .= "Posted on ";
$html .= $item->get_date('j F Y | g:i a');
$html .= '</small></p>';
$html .= '</article>';
}
}
print_r($html);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.