Fork me on GitHub
Current releases are 2.1.3 (9 Sept 2014) and 2.0.18.13 (5 Aug 2014)

Ready for 2.1? Find out if your plugins are compatible. 2.0 will no longer be updated after Dec 2014.

Displaying category description

TudorTudor
edited July 2010 in Vanilla 2.0 Help
How can I display the categories descriptions in the category list?

And also on the category page?

Comments

  • Nevermind, I figured out myself. :)
  • To add the category description on the category page:
    - Create a custom theme
    - You have to customize a "views" file (see the Theme QuickStart page). In this case it's /applications/vanilla/discussions/helper_functions.php. You don't have to modify the original one, just copy it into /themes/Your_Custom_Theme/views/discussions/helper_functions.php.
    - Somewhere around line 100 you'll see this:


    if (property_exists($Sender, 'Category') && is_object($Sender->Category)) {
    ?>
    <div class="SubTab">↳ <?php echo $Sender->Category->Name; ?></div>
    <?php
    }


    I replaced it with this:


    if (property_exists($Sender, 'Category') && is_object($Sender->Category)) {
    ?>
    <h2 class="DTPCategoryName"><?php echo $Sender->Category->Name; ?></h2><p class="DTPCategoryDesc"><?php echo $Sender->Category->Description; ?></p>
    <?php
    }
    ?>


    And you can see the result here.
  • To add the category description on the category page:
    - Create a custom theme
    - You have to customize a "views" file (see the Theme QuickStart page). In this case it's /applications/vanilla/discussions/helper_functions.php. You don't have to modify the original one, just copy it into /themes/Your_Custom_Theme/views/discussions/helper_functions.php.
    - Somewhere around line 100 you'll see this:


    if (property_exists($Sender, 'Category') && is_object($Sender->Category)) {
    ?>
    <div class="SubTab">↳ <?php echo $Sender->Category->Name; ?></div>
    <?php
    }


    I replaced it with this:


    if (property_exists($Sender, 'Category') && is_object($Sender->Category)) {
    ?>
    <h2 class="DTPCategoryName"><?php echo $Sender->Category->Name; ?></h2><p class="DTPCategoryDesc"><?php echo $Sender->Category->Description; ?></p>
    <?php
    }
    ?>


    And you can see the result here.
  • TudorTudor
    edited July 2010
    Oops, sorry for posting twice.
    And remove all the < br / > from the code, they were inserted by the forum here (< code > tag parsing bugs?)
  • good to know. Many many thanks :)
  • Rardor81Rardor81 New
    edited March 2011
    This works great. Is there any way though to get it in the sidebar panel?
  • I did this too, in the discussions view to show the description at the top of each category listing. I also did this to make formatting the description a little easier:

    Gdn_Format::To($sender->Category->Description, 'markdown')

    This allows *markdown* to be _used_ in the description to tart it up a bit, avoiding the need to add HTML tags (which affect the admin views of the categories).
  • LincLinc Community Instigator Detroit Vanilla Staff
    Tart it up. Awesome. :D

    Sr Developer at Vanilla Forums [GitHub, Twitter] and humble servant of Lord Brackos.

  • It's what we used to say in the UK years before people "pimped" their wagon.
  • would have been great. but the code has changed. helper_functions.php is no longer what it used to be :-(

  • PamelaPamela ✭✭

    happy2b said: would have been great. but the code has changed. helper_functions.php is no longer what it used to be :-(

    aarch :( you 're right... I can't find this suggested code in the latest v2.0.18.4

    Nobody could help us? thanks in advance

  • @Pamela said: happy2b said: would have been great. but the code has changed. helper_functions.php is no longer what it used to be :-(

    yea trying to do that in the latest 2.1 version.... codes are not hte same

  • I stumbled upon this from Google, thought I'd update it for anyone wanting to know.

    File to edit: /vanilla/views/categories/discussions.php

    +22: <div><?php echo $Category->Description; ?></div>

    That's all I had to add to get mine to work, you can also add this file as a view to your theme with the same structured layout as above (/vanilla/themes/[name]/views/categories/discussions.php). Hope this helps someone, this is for version 2.1.2 and it should be pretty self explanatory after opening that file.

    Thanks

  • peregrineperegrine ☯ hasta luego :) In-Flight MVP
    edited September 8

    @Taco said: I stumbled upon this from Google, thought I'd update it for anyone wanting to know.

    File to edit: /vanilla/views/categories/discussions.php

    +22: <div><?php echo $Category->Description; ?></div>

    That's all I had to add to get mine to work, you can also add this file as a view to your theme with the same structured layout as above (/vanilla/themes/[name]/views/categories/discussions.php). Hope this helps someone, this is for version 2.1.2 and it should be pretty self explanatory after opening that file.

    Thanks

    just a thought, might be cleaner with a theme hook checking the AfterCategoryTitle event.

    then you can avoid changing view.

    on the categories discussions page. descriptions seem to show elsewhere without any changes.

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

  • peregrineperegrine ☯ hasta luego :) In-Flight MVP
    edited September 8

    although it might be better if the event were moved out of the h2 tag

     <div class="CategoryBox Category-<?php echo $Category->UrlCode; ?>">      
          <h2 class="H"><?php
                echo Anchor(htmlspecialchars($Category->Name), CategoryUrl($Category));
                Gdn::Controller()->EventArguments['Category'] = $Category;
                Gdn::Controller()->FireEvent('AfterCategoryTitle'); 
          ?></h2>
    

    to

    <div class="CategoryBox Category-<?php echo $Category->UrlCode; ?>">      
          <h2 class="H"><?php
                echo Anchor(htmlspecialchars($Category->Name), CategoryUrl($Category));
                Gdn::Controller()->EventArguments['Category'] = $Category;
          ?></h2>
    
               <?php      Gdn::Controller()->FireEvent('AfterCategoryTitle'); ?>
    

    otherwise you would probably need to close the h2 tag and reopen in the insertion to avoid doing getting the description as part of h2

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

    vrijvlinder
Sign In or Register to comment.