简体   繁体   English

如何在Drupal 7中更改单个节点的每页评论数?

[英]How to change the number of comments per page for a single node in Drupal 7?

i would like to change the comments per page for only a single node. 我只想为单个节点更改每页的注释。 Let's say that the defaul number of comments per page for the content type "article" is 50 and i want change this to 10 only for the article with nid=171. 假设内容类型“文章”的每页注释的默认值为50,而我只想将nid = 171的文章的注释数更改为10。

$node = menu_get_object('node',1); if($node && $node->nid = 171) {......}

Any hint? 有什么提示吗? Thanks. 谢谢。

If you want to control the number of comments on individual pages, I would suggest installing Views module which allow for easy creation of any lists of things, including comments. 如果要控制单个页面上的评论数量,建议安装Views模块,该模块可轻松创建所有事物列表,包括评论。 With Views, you can create a block with comments for any node and use that instead of regular comments block. 使用“视图”,可以为任何节点创建一个带注释的块,并使用该块代替常规注释块。 Also, you can have several different blocks with different number of comments, and attach whatever block you want to whatever node. 另外,您可以具有带有不同数量注释的几个不同块,并将所需的任何块附加到任何节点。 Using Context module would help too, it allows to assign blocks and other elements to pages with much more sophisticated controls than Drupal core block management. 使用上下文模块也将有所帮助,它允许将块和其他元素分配给具有比Drupal核心块管理更为复杂的控件的页面。

Check out can this be helpful to you: 查看这是否对您有帮助:

https://drupal.stackexchange.com/questions/7450/comment-per-page-settings https://drupal.stackexchange.com/questions/7450/comment-per-page-settings

Since it's a form you have to alter it and change comments number from code. 由于它是一种表格,因此您必须更改它并从代码中更改注释编号。

i found a solution even if a bit rude. 即使有点不礼貌,我也找到了解决方案。 To disable the node's default comments i used a preprocess function in template.php file of my subtheme and disbled the $content['comments'] variable used in the comment-wrapper.tpl.php template: 为了禁用节点的默认注释,我在子主题的template.php文件中使用了预处理功能,并取消了comment-wrapper.tpl.php模板中使用的$content['comments']变量:

function MYSUBTHEMENAME_preprocess_comment_wrapper(&$vars){
$node = menu_get_object();
if($node):
if($node->type === 'forum' && $node->nid == 171):
unset($vars['content']['comments']);
endif;
endif;
}

Note that i did it for comment wrapper variables/template and not for the node vfariables/template in order to unset the comments but to keep the comment form. 请注意,我这样做是为了注释包装变量/模板,而不是为了节点vfariables / template,以便取消设置注释,但保留注释表单。

Then i created a view block of comments with a filter for the nid of the comment's node. 然后,我为评论的节点创建了一个带有过滤器的评论视图块。 This works well for my purposes but if you find a more elegant way let me know. 这对我来说很有效,但是如果您找到更优雅的方式,请告诉我。 :) :)

I spent a time looking comment.module and found this in comment_form_node_type_form_alter 我花了一些时间查看comment.module,并在comment_form_node_type_form_alter找到了它

$form['comment']['comment_default_per_page'] = array(
      '#type' => 'select',
      '#title' => t('Comments per page'),
      '#default_value' => variable_get('comment_default_per_page_' . $form['#node_type']->type, 50),
      '#options' => _comment_per_page(),
    );

So I put that in my template.php 所以我把它放在我的template.php中

function THEMENAME_preprocess_page(&$variables){
  if (isset($variables['node']->type)) {
     if ($variables['node']->type == 'forum') {
         variable_set('comment_default_per_page_' . 'forum', 4);
     }
  }
}

It worked for me, I hope it helps. 它为我工作,希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM