代码之家  ›  专栏  ›  技术社区  ›  choise

在页面和帖子之外使用评论系统

  •  4
  • choise  · 技术社区  · 15 年前

    所以现在我用的是 pods

    现在我想对每一页使用评论系统,例如:

    mydomain.com/podpages/page1
    mydomain.com/podpages/page2
    mydomain.com/podpages/page3
    

    用wordpress创建的页面只需添加 <?php comments_template(); ?> 不起作用。

    有什么办法解决这个问题吗?

    5 回复  |  直到 5 年前
        1
  •  11
  •   TheDeadMedic    15 年前

    当评论存储在WordPress数据库中时,评论所涉及的文章(或页面)的ID也会被存储。

    知道 关于。

    文字出版社 每一页 页面,但仅作为 ,这样您的真实页面和WordPress就有了一个共同点,可以相互协作。

    • 在每个“真实”页面的背景中加载WordPress。
    • 如果没有,就创建它,然后就在那里
    • 欺骗WordPress,使其认为我们实际上是在查看表示

    include ('../path/to/wp-load.php');
    
    // remove query string from request
    $request = preg_replace('#\?.*$#', '', $_SERVER['REQUEST_URI']);
    
    // try and get the page name from the URI
    preg_match('#podpages/([a-z0-9_-]+)#', $matches);
    
    if ($matches && isset($matches[1])) {
        $pagename = $matches[1];
    
        // try and find the WP representation page
        $query = new WP_Query(array('pagename' => $pagename));
    
        if (!$query->have_posts()) {
            // no WP page exists yet, so create one
            $id = wp_insert_post(array(
                'post_title' => $pagename,
                'post_type' => 'page',
                'post_status' => 'publish',
                'post_name' => $pagename
            ));
    
            if (!$id)
                do_something(); // something went wrong
        }
    
        // this sets up the main WordPress query
        // from now on, WordPress thinks you're viewing the representation page       
    }
    

    更新

    我真不敢相信我这么笨。下面的代码应该替换外部代码 if ;

    // try and find the WP representation page - post_type IS required
    $query = new WP_Query(array('name' => $pagename, 'post_type' => 'page'));
    
    if (!$query->have_posts()) {
        // no WP page exists yet, so create one
        $id = wp_insert_post(array(
            'post_title' => $pagename,
            'post_type' => 'page',
            'post_status' => 'publish',
            'post_name' => $pagename,
            'post_author' => 1, // failsafe
            'post_content' => 'wp_insert_post needs content to complete'
        ));
    }
    
    // this sets up the main WordPress query
    // from now on, WordPress thinks you're viewing the representation page
    // post_type is a must!
    wp(array('name' => $pagename, 'post_type' => 'page'));
    
    // set up post
    the_post(); 
    

    name pagename

    您还需要在表单中输入name redirect_to 以及要重定向到的URL的值, comment_post_redirect

        2
  •  0
  •   Galen    15 年前

    添加

    require('/path/to/wp-blog-header.php');
    

        3
  •  0
  •   BillThor    15 年前

    你能在wordpress中创建显示日志数据的页面吗?你可能需要一个新的模板。WordPress将有一些东西来连接评论。

        4
  •  0
  •   Community CDub    8 年前

    你需要用WordPress吗?如果没有,也许这个问题有帮助: Unobtrusive, self-hosted comments function to put onto existing web pages

        5
  •  0
  •   ShoX    15 年前

    只需给wordpress评论部分提供一个新的ID-从一些你通常的帖子永远无法到达的内容开始(100.000+是你的页面,即)

    我不知道在wordpress中它是否是一个函数(即saveComment),但是如果是这样的话,就在你的页面中用它来定制ID。

    不要忘了修改查询,以获取IDs超过100.000不是条目的新闻实体。

    或者您可以编写自己的模板,用id<显示标准的Worpress文件;10万,否则你的网页。

    推荐文章