Wordpress帖子可以动态呈现吗?

 Openset 发布于 2023-02-09 10:57

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

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

1 个回答
  • 作为解决方案,您可以使用404页面生成此动态帖子。

    这里有一篇博客文章提供了类似的解决方案: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文件。

    2023-02-09 11:00 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有