我有一个自定义的页面在WordPress的自定义模板。除了显示用户的实际页面,它还通过在URL变量传递动态创建页面。
因此,我在wordpress中创建了一个名为News的页面,并将其分配给我的news.php模板。mywebsite.com/news
他们也可以后藤mywebsite.com/news/2012/august-8/,页面模板通过这些url变量读取日期,并显示该页面的新闻。
这是我想做的,我想在“日期特定页面”中添加注解,这些页面并不是wordpress中的实际页面,而是基于url变量动态创建的。
我可以添加comments_template()到页面,但我相信它是基于页面ID或帖子ID的...有没有一种方法可以插入自定义ID或插入URL来为这些动态页面创建评论?
我不希望www.example.com上的评论mywebsite.com/news/2012/august-8/出现在www.example.com上mywebsite.com/news/2012/august-9/---它们是单独的页面
有什么想法
3条答案
按热度按时间lskq00tm1#
我理解你,但我认为这不是一个好主意,以这种方式使用WP.你搞乱了WP的主要功能,他们的帖子和评论.我应该使用另一个框架这项工作.任何方式一个好的起点调查是
wp_commentmeta
表和他们的朋友:相信你能达到你所需要的。
cu6pst1q2#
我知道这个问题已经很老了,但我还是要把答案贴出来,以防人们还在寻找。老实说,我认为这个功能应该包含在创建动态用户配置文件类型页面的插件中,我不知道为什么开发人员要添加这个功能。
只要它们是动态页面中唯一的url的一部分,这个方法就可以工作。在我的例子中,我使用url的第二部分。
1.首先,你想在评论中添加一个隐藏的评论字段,它可以抓取部分或全部的url并填充到文本框中,你可以对你网站上的所有评论都这样做,或者你可以像我一样使用if查询,如果你只需要在一个父页面上使用它。
1.接下来,你可以确保这个文本框作为额外的注解元数据发布到你的wp_commentmeta表中。现在你有了一个唯一的id,每个发布到特定url的注解都可以查询数据库。
查询以显示具有 meta值的评论,该元值与我们刚刚保存到commentmeta表的url部分相匹配。这将进入您的父帖子页面模板,即在本示例中为第108页
xytpbqjk3#
@Rob:很棒的方法,非常感谢!在我遇到你的帖子之前,我已经花了几个小时来详细说明如何在动态生成的页面上进行评论。
只是几句话:
输入ID=“hiddencomment”name=“hiddencomment”placeholder="' . __('hiddencomment','Extra Field'). '”value=“'.$lastpart[2].'" type=“text”size=“30”
$comments = get_comments(array(' meta_key' =〉'title','meta_value' =〉$customer_id));
再次感谢!最好的,简