Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.08 KB | None | 0 0
  1. function yourtheme_get_node_count($content_type) {
  2. $query = "SELECT COUNT(*) FROM {node} n ".
  3. "WHERE n.type = :type";
  4. $total = db_query($query, array(':type' => $content_type))->fetchField();
  5. return $total;
  6. }
  7.  
  8. echo 'Pages: ' . YOURTHEME_get_node_count('page');
  9. echo 'Products: ' . YOURTHEME_get_node_count('product');
  10.  
  11. $view = new view;
  12. $view->name = 'nodecounts';
  13. $view->description = '';
  14. $view->tag = 'default';
  15. $view->base_table = 'node';
  16. $view->human_name = 'Node counts';
  17. $view->core = 7;
  18. $view->api_version = '3.0';
  19. $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  20.  
  21. /* Display: Master */
  22. $handler = $view->new_display('default', 'Master', 'default');
  23. $handler->display->display_options['title'] = 'Node counts';
  24. $handler->display->display_options['group_by'] = TRUE;
  25. $handler->display->display_options['access']['type'] = 'perm';
  26. $handler->display->display_options['cache']['type'] = 'none';
  27. $handler->display->display_options['query']['type'] = 'views_query';
  28. $handler->display->display_options['query']['options']['query_comment'] = FALSE;
  29. $handler->display->display_options['exposed_form']['type'] = 'basic';
  30. $handler->display->display_options['pager']['type'] = 'none';
  31. $handler->display->display_options['style_plugin'] = 'default';
  32. $handler->display->display_options['row_plugin'] = 'fields';
  33. $handler->display->display_options['row_options']['inline'] = array(
  34. 'type_1' => 'type_1',
  35. 'type' => 'type',
  36. );
  37. $handler->display->display_options['row_options']['separator'] = ': ';
  38. $handler->display->display_options['row_options']['hide_empty'] = 0;
  39. $handler->display->display_options['row_options']['default_field_elements'] = 1;
  40. /* Field: Content: Type */
  41. $handler->display->display_options['fields']['type_1']['id'] = 'type_1';
  42. $handler->display->display_options['fields']['type_1']['table'] = 'node';
  43. $handler->display->display_options['fields']['type_1']['field'] = 'type';
  44. $handler->display->display_options['fields']['type_1']['label'] = '';
  45. $handler->display->display_options['fields']['type_1']['alter']['alter_text'] = 0;
  46. $handler->display->display_options['fields']['type_1']['alter']['make_link'] = 0;
  47. $handler->display->display_options['fields']['type_1']['alter']['absolute'] = 0;
  48. $handler->display->display_options['fields']['type_1']['alter']['external'] = 0;
  49. $handler->display->display_options['fields']['type_1']['alter']['replace_spaces'] = 0;
  50. $handler->display->display_options['fields']['type_1']['alter']['trim_whitespace'] = 0;
  51. $handler->display->display_options['fields']['type_1']['alter']['nl2br'] = 0;
  52. $handler->display->display_options['fields']['type_1']['alter']['word_boundary'] = 1;
  53. $handler->display->display_options['fields']['type_1']['alter']['ellipsis'] = 1;
  54. $handler->display->display_options['fields']['type_1']['alter']['strip_tags'] = 0;
  55. $handler->display->display_options['fields']['type_1']['alter']['trim'] = 0;
  56. $handler->display->display_options['fields']['type_1']['alter']['html'] = 0;
  57. $handler->display->display_options['fields']['type_1']['element_label_colon'] = FALSE;
  58. $handler->display->display_options['fields']['type_1']['element_default_classes'] = 1;
  59. $handler->display->display_options['fields']['type_1']['hide_empty'] = 0;
  60. $handler->display->display_options['fields']['type_1']['empty_zero'] = 0;
  61. $handler->display->display_options['fields']['type_1']['hide_alter_empty'] = 1;
  62. $handler->display->display_options['fields']['type_1']['link_to_node'] = 0;
  63. $handler->display->display_options['fields']['type_1']['machine_name'] = 0;
  64. /* Field: COUNT(Content: Type) */
  65. $handler->display->display_options['fields']['type']['id'] = 'type';
  66. $handler->display->display_options['fields']['type']['table'] = 'node';
  67. $handler->display->display_options['fields']['type']['field'] = 'type';
  68. $handler->display->display_options['fields']['type']['group_type'] = 'count';
  69. $handler->display->display_options['fields']['type']['label'] = '';
  70. $handler->display->display_options['fields']['type']['alter']['alter_text'] = 0;
  71. $handler->display->display_options['fields']['type']['alter']['make_link'] = 0;
  72. $handler->display->display_options['fields']['type']['alter']['absolute'] = 0;
  73. $handler->display->display_options['fields']['type']['alter']['external'] = 0;
  74. $handler->display->display_options['fields']['type']['alter']['replace_spaces'] = 0;
  75. $handler->display->display_options['fields']['type']['alter']['trim_whitespace'] = 0;
  76. $handler->display->display_options['fields']['type']['alter']['nl2br'] = 0;
  77. $handler->display->display_options['fields']['type']['alter']['word_boundary'] = 1;
  78. $handler->display->display_options['fields']['type']['alter']['ellipsis'] = 1;
  79. $handler->display->display_options['fields']['type']['alter']['strip_tags'] = 0;
  80. $handler->display->display_options['fields']['type']['alter']['trim'] = 0;
  81. $handler->display->display_options['fields']['type']['alter']['html'] = 0;
  82. $handler->display->display_options['fields']['type']['element_label_colon'] = FALSE;
  83. $handler->display->display_options['fields']['type']['element_default_classes'] = 1;
  84. $handler->display->display_options['fields']['type']['hide_empty'] = 0;
  85. $handler->display->display_options['fields']['type']['empty_zero'] = 0;
  86. $handler->display->display_options['fields']['type']['hide_alter_empty'] = 1;
  87. $handler->display->display_options['fields']['type']['separator'] = '';
  88. $handler->display->display_options['fields']['type']['format_plural'] = 0;
  89.  
  90. /* Display: Block */
  91. $handler = $view->new_display('block', 'Block', 'block');
  92.  
  93. $query = new EntityFieldQuery();
  94.  
  95. $query->entityCondition('entity_type', 'node') // grab nodes
  96. ->entityCondition('bundle', 'blog') // filter by blog type
  97. ->propertyCondition('status', 1) // filter by published
  98. ->count(); // count
  99.  
  100. $result = $query->execute();
  101.  
  102. $query = new EntityFieldQuery();
  103. $query->entityCondition('entity_type', 'node')
  104. /* this is the content type machine name */
  105. ->entityCondition('bundle', 'product')
  106. /* You can set extra properties using fieldCondition and properties with propertyCondition */
  107. ->fieldCondition('field_product_status', 'tid', key(taxonomy_get_term_by_name('New')))
  108. ;
  109.  
  110. $result = $query->execute();
  111. if (isset($result['node'])){
  112. $count_of_new_product_nodes = count($result['node']);
  113. }
  114.  
  115. drush sqlq 'select count(node.nid) as node_count, node_type.type from node inner join node_type on node.type = node_type.type group by node_type.type'
  116.  
  117. node_count type
  118. 17 category_2012
  119. 20 category_2013
  120. 19 category_2014
  121. 3 competition
  122. 19 entry_2012_breakthrough
  123. 89 entry_2012_digitalother
  124. 50 entry_2012_directdirect
  125. 19 entry_2012_filmsecscn
  126. 17 entry_2012_insights
  127. 12 entry_2012_outdoor
  128. 31 entry_2012_promo
  129. 19 entry_2013_breakthrough
  130. 100 entry_2013_digitalother
  131. 40 entry_2013_directdirect
  132.  
  133. drush sqlq 'select count(node.nid) as node_count, node_type.type from node inner join node_type on node.type = node_type.type group by node_type.type' | grep 2014
  134.  
  135. $count = db_select('node')
  136. ->condition('type', 'some-type')
  137. ->countQuery()->execute()->fetchField();
  138.  
  139. SELECT
  140. COUNT({node}.nid) AS node_count,
  141. {node_type}.type
  142. FROM {node}
  143. INNER JOIN {node_type} ON {node}.type = {node_type}.type
  144. GROUP BY {node_type}.type;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement