How do I post a list of categories on a block?

Comments

aslack’s picture

can someone please help with this! How do I create categories that can be found on a block. Thanks!

sepeck’s picture

You are being to vague. Think about what you are wanting to do and present it a little more.

There are several posible ways in the cutom blocks repository too.
http://drupal.org/node/21866

Maybe this as well.
http://drupal.org/project/article

-sp
---------
Test site...always start with a test site.
Drupal Best Practices Guide

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

Lam0r’s picture

Since your question wasnt really clear I will just assume..

If you want to display a list of categories in your database use the following code in the block and set the block to php

<?php
if (user_access('access content')) {
  $result = db_query("SELECT d.tid, d.name, MAX(n.created) AS updated, COUNT(*) AS count FROM {term_data} d INNER JOIN {term_node} USING (tid) INNER JOIN {node} n USING (nid) WHERE n.status = 1 GROUP BY d.tid, d.name ORDER BY updated DESC, d.name");
  $items = array();
  while ($category = db_fetch_object($result)) {
    $items[] = l($category->name .' ('. $category->count .')', 'taxonomy/term/'. $category->tid) .'<br />'. t('%time ago', array('%time' => format_interval(time() - $category->updated)));
  }
  return theme('item_list', $items);
}
?> 

I got this code of the forum sometime back and it works fine for me.

gobblez’s picture

Thanks this was just what I needed. I've tried 3 different modules so far trying to do this.

I wanted a block that had a list of all categories that a story can be. This code snippet gives me really close to what I need.
--------------
categories
--------------
| Example (3 articles)
| SomethingElse (1 article)
| Another category (8 articles)
| etc...