2

カテゴリ用語 (ブロック内に含まれる) のリストを作成したいと思います。各用語の後に、その用語を持つノードの数が続きます。たとえば、次のようになります。

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>

つまり、リスト全体ではなく、カウントのみが動的である必要があります (用語自体は変更されないため、これで問題ありません)。Drupal の機能が役立つかもしれないと聞いたことtaxonomy_term_count_nodes()がありますが、その実装に関する簡単な情報が見つかりません。

4

6 に答える 6

8

その実装に関してどのような情報が必要ですか? ドキュメントはかなり明確なようです...

<?php print taxonomy_term_count_nodes($term_id); ?>
于 2009-10-28T18:46:15.093 に答える
3

私はそれを数回しました。IMO ビューを使用して、タクソノミー用語のみをリストするノード ビューを作成し、http://drupal.org/project/views_groupbyモジュールを使用して、用語の横にその用語を含むノードの数を配置することをお勧めします。views_groupby ドキュメントの例は、知っておくべきことを示しています。

カスタム モジュールは明らかにもう少し柔軟性がありますが、上記を考えると最終的には不要です。

于 2009-10-28T21:15:52.763 に答える
2

ドキュメントに欠けている情報もわかりません。例が役立つかもしれません。以下は、語彙内のすべての用語の順序付きリストを作成し、それらのノード数を追加します (テストされていないため、タイプミスがある可能性があります)。

// 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;
于 2009-10-28T23:14:28.787 に答える
1

Drupal 7 でTaxonomy_term_count_nodesが存在しない

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);
于 2015-06-09T05:50:32.207 に答える
0

taxonomy_select_nodes で 10 件の結果しか得られない場合は、この関数で Pager がデフォルトで true に設定されているため、「FALSE」で次のようにする必要があります。

$data = taxonomy_select_nodes($term_id, FALSE);
$count = count($data);
于 2015-12-24T08:57:08.963 に答える