Wordpress帖子可以动态呈现吗? [英] Can Wordpress posts be rendered dynamically?

查看:170
本文介绍了Wordpress帖子可以动态呈现吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个博客页面,该页面根据他/她的Facebook喜欢,活动等为特定用户生成内容。例如,我喜欢Facebook上的Shakira和可口可乐。当进入博客并通过Facebook连接时,博客获得该信息,并通过YouTube API搜索Shakira的YouTube视频,并在WordPress的帖子中向我显示视频。博客搜索与可口可乐相关的新闻,并在一篇文章中显示新闻。

I want to make a blog page which is generating content for particular user based on his/her Facebook likes, activity etc. For example I like Shakira and Coca Cola on Facebook. When entering the blog and connecting via Facebook, the blog gets that info and searches for Shakira's YouTube video through YouTube API and shows me the video in a WordPress post. After the blog searches for news connected with Coca Cola and shows news about it also in a post.

FB连接,YouTube搜索或Google搜索没有问题。我的问题是WordPress。由于可以有很多用户和大量的内容可以为每个用户生成,我无法保存MySQL表中的每个帖子。我想动态地生成帖子。我不是在这里要求代码,我只想听到很好的解决方案和想法如何做到这一点。

There is no problem with FB connect, YouTube search or Google search. My problem is WordPress. As there can be a lot of users and a lot of content can be generated for each user, I can't save every post in MySQL table. I want to generate posts dynamically. I'm not asking for code here, I just want to hear good solutions and ideas how can this be done.

推荐答案

作为解决方案,您可以使用404页面来生成此动态文章。

As a solution you could use the 404 page to generate this dynamic post.

这里有一篇博文,提供了类似的解决方案: http://www.blogseye.com/creating-fake-wordpress-posts-on-the-fly/

There's a blog post here that gives a similar solution: http://www.blogseye.com/creating-fake-wordpress-posts-on-the-fly/

用于生成的代码假的帖子:

The code used to generate the fake posts:

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文件中。

Make this into a plugin or add it to the functions.php file.

这篇关于Wordpress帖子可以动态呈现吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆