Drupal의 각 카테고리 용어에 대한 노드 수를 어떻게 작성합니까?

StackOverflow https://stackoverflow.com/questions/1639267

  •  08-07-2019
  •  | 
  •  

문제

카테고리 용어 목록 (블록 내에 포함)을 만들고 싶습니다. 각 용어에 이어 해당 용어를 가진 노드 수의 수를 다음과 같이합니다.

Cats (5)
Dogs (4)
Elephants (2)

이와 같은 전체 목록을 동적으로 생성하는 많은 모듈이 있지만, 내 목적에 대한 단점이 모두 있음을 발견했습니다. 나는 말 그대로 다음과 같은 것이 필요합니다.

<ul>
<li><a href="mylink">Cats</a> (<?php ...some code... ?>)</li>
<li><a href="mylink">Dogs</a> (<?php ...some code... ?>)</li>
<li><a href="mylink">Elephants</a> (<?php ...some code... ?>)</li>
</ul>

즉, 전체 목록이 아니라 역동적이기 위해서만 카운트 만 있으면됩니다 (용어 자체가 변경되지 않기 때문에 괜찮습니다). 드 루팔 기능이 들렸다 고 들었습니다 taxonomy_term_count_nodes() 유용 할 수 있지만 구현에 관한 간단한 정보를 찾을 수는 없습니다.

도움이 되었습니까?

해결책

구현과 관련하여 어떤 정보를 원하십니까? 문서 꽤 분명해 보인다 ...

<?php print taxonomy_term_count_nodes($term_id); ?>

다른 팁

나는 그 일을 몇 번했다. IMO는 뷰를 사용하여 분류 용어를 나열한 노드 뷰를 만들고 다음을 사용하는 것이 좋습니다. http://drupal.org/project/views_groupby 모듈 용어 옆에 해당 용어로 노드 수를 넣는 모듈. 예제 views_groupby 문서 알아야 할 사항을 알려줍니다.

사용자 정의 모듈은 분명히 좀 더 유연하지만 궁극적으로 위의 점에서 불필요합니다.

또한 문서에 어떤 정보가 누락되었는지 잘 모르겠습니다. 예를 들어 도움이 될 수 있습니다. 다음은 어휘 내에서 모든 용어 목록을 작성하고 노드 카운트가 첨부되어 있으므로 오타가있을 수 있습니다.

// Adjust this to the id of the vocabulary holding your terms
$vid = 1;
// Grab all terms in that vocabulary
$terms = taxonomy_get_tree($vid);
$items = array();
foreach ($terms as $term) {
  // Get the number of (published) nodes with that term
  $count = taxonomy_term_count_nodes($term->tid);
  // Assemble your link text
  $text = $term->name . ' (' . $count . ')';
  // Set this to the path you want to link to (default term views used here)
  $path = 'taxonomy/term/' . $term->tid;
  // Turn the above into a rendered link
  $link = l($text, $path);
  // Add to items
  $items[] = $link;
}
// Render array as an ordered list
$list = theme('item_list', $items, NULL, 'ol');

print $list;

분류 _term_count_nodes Drupal 7에서 나가지 않습니다

Drupal 7에는 분류 용어 노드를 얻는 또 다른 동등한 API가 있습니다. 여기 API가 있습니다 https://api.drupal.org/api/drupal/modules !taxonomy !taxonomy.module/funct...

배열 값을 반환하고 PHP로 배열 값을 계산할 수 있습니다.

<?php 
  $data = taxonomy_select_nodes($tid);
  $count = count($data);

Drupal 7에서는 실제로보기 로이 작업을 수행 할 수 있습니다. 코딩이나 추가 모듈이 필요하지 않습니다. 보다 View Aggregator를 사용하여 분류기 카운트 블록을 생성하는 방법은 무엇입니까? 자세한 내용은.

분류 _select_nodes로 10 개의 결과 만 받으면이 기능에서 호출기가 기본적으로 TRUE로 설정되어 있으므로 'false'를 사용하여 다음과 같이 수행해야합니다.

$data = taxonomy_select_nodes($term_id, FALSE);
$count = count($data);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top