Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Displaying category description

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

And also on the category page?

Comments

  • Nevermind, I figured out myself. :)
  • and how? ;)
  • 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 :)
  • oliverraduneroliverraduner Contributing to Vanilla since 2010 Switzerland ✭✭
  • 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 Detroit Admin
    Tart it up. Awesome. :D
  • 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 MVP
    edited September 2014

    @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.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited September 2014

    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

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.