How to list site-wide categories?

I've enabled the categories plugin but I can't seem to display them manually. Here's the code:

<?php

$site = elgg_get_site_entity();
$categories = $site->categories;

echo $categories;

?>

var_dump($categories) shows me a NULL value.

  • This plugin is a little bit tricky. It doesn't have a page where you can see all the site categories listed. It looks like it was done in a lazy way.

    This is how I show the categories (To select)

    $categories = elgg_view('input/categories', $vars);
    if ($categories) {
        echo $categories;
    }

     

  • Doesn't work. I'm trying to list the categories on the sidebar of blogs but all I'm getting is NULL. Any devs wanna put their input?

  • This may seem like a stupid question but are you sure you have categories defined?

  • What do you mean Matt? I have a bunch of categories inputted in the admin section.

    image

  • I'm not sure what I did but it's showing up now, weird! I turned on xoxco_tags, went back to site-wide categories and the input box was empty but the categories were showing up in the blog. Weird!

  • If you guys want the code to list all categories as URLs instead of tags, here it is:

    <?php

    // Get site categories
    $site = elgg_get_site_entity();
    $categories = $site->categories;

    if (empty($categories)) {
    $categories = array();
    }

    if (!empty($categories)) {
    if (!is_array($categories)) {
    $categories = array($categories);
    }
    foreach($categories as $category) {
    $link = elgg_get_site_url() . 'categories/list?category=' . urlencode($category);
    if (!empty($linkstr)) {
    $linkstr .= ' - ';
    }
    $linkstr .= '<a href="'.$link.'">' . $category . '</a>';
    }
    }

    echo '<div class="elgg-module elgg-module-aside">';
    echo '<div class="elgg-head">';
    echo '<h3>Categories</h3>';
    echo '</div>';
    echo $linkstr;
    echo '</div>';

    ?>