我想制作一个博客页面,根据特定用户的 Facebook 点赞、活动等生成内容。例如,我喜欢 Facebook 上的 Shakira 和可口可乐。当进入博客并通过 Facebook 连接时,博客会获取该信息并通过 YouTube API 搜索 Shakira 的 YouTube 视频,并在 WordPress 帖子中向我展示该视频。该博客搜索与可口可乐相关的新闻并在帖子中显示有关它的新闻。
FB connect、YouTube 搜索或 Google 搜索都没有问题。我的问题是WordPress。由于可能有很多用户,并且可以为每个用户生成很多内容,所以我无法在 MySQL 表中保存每个帖子。我想动态生成帖子。我不是在这里要求代码,我只是想听到好的解决方案和想法如何做到这一点。
作为解决方案,您可以使用 404 页面来生成此动态帖子。
这里有一篇博客文章提供了类似的解决方案:http://www.blogseye.com/creating-fake-wordpress-posts-on-the-fly/ http://www.blogseye.com/creating-fake-wordpress-posts-on-the-fly/
用于生成假帖子的代码:
function kpg_f_content() {
global $wp_query;
if($wp_query->is_404 ) {
$id=-42; // need an id
$post = new stdClass();
$post->ID= $id;
$post->post_category= array('uncategorized'); //Add some categories. an array()???
$post->post_content='hey here we are a real post'; //The full text of the post.
$post->post_excerpt= 'hey here we are a real post'; //For all your post excerpt needs.
$post->post_status='publish'; //Set the status of the new post.
$post->post_title= 'Fake Title'; //The title of your post.
$post->post_type='post'; //Sometimes you might want to post a page.
$wp_query->queried_object=$post;
$wp_query->post=$post;
$wp_query->found_posts = 1;
$wp_query->post_count = 1;
$wp_query->max_num_pages = 1;
$wp_query->is_single = 1;
$wp_query->is_404 = false;
$wp_query->is_posts_page = 1;
$wp_query->posts = array($post);
$wp_query->page=false;
$wp_query->is_post=true;
$wp_query->page=false;
}
}
add_action('wp', 'kpg_f_content');
将其制作为插件或将其添加到functions.php 文件中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)