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.

Show tags under discussion title

422422 MVP
edited December 2011 in Vanilla 2.0 - 2.8

Is there a way of showing tags created for a thread, under the discussions title on main forum index page ?

There was an error rendering this rich post.

Tagged:

Best Answers

  • KastangKastang New
    edited December 2011 Answer ✓

    If you copy

    /applications/vanilla/views/discussions/helper_functions.php

    to

    /themes/[YOURTHEME]/views/discussions/helper_functions.php

    you can add the tags string to the discussions by adding:

    if($Discussion->Tags != '') { echo '<span class="DiscussionTags">Tags: '.$Discussion->Tags.'</span>'; }

    directly before

    $Sender->FireEvent('DiscussionMeta');

    located at the bottom of the file.

  • KastangKastang New
    edited December 2011 Answer ✓

    Try this:

    if($Discussion->Tags != '') { $Tags = explode(' ',$Discussion->Tags); $String = ""; foreach($Tags as $t) { $String .= "<a href='index.php?p=discussions/tagged/".rawurlencode($t)."'>$t</a> "; } echo '<span class="DiscussionTags">Tags: '.$String.'</span>'; }

    The above is assuming you are NOT using URL Rewriting. If you are, change the $String variable in the foreach loop to:

    $String .= "<a href='discussions/tagged/".rawurlencode($t)."'>$t</a> ";

  • KastangKastang New
    edited December 2011 Answer ✓

    Move:

    /applications/vanilla/views/discussion/helper_functions.php

    To:

    /themes/[YOURTHEME]/views/discussion/helper_functions.php

    Add:

    <? if($Sender->Discussion->Tags != '' && $Type != 'Comment') { $Tags = explode(' ',$Sender->Discussion->Tags); $String = ""; foreach($Tags as $t) { $String .= "<a href='"; $String .= (strstr($Sender->Form->Action, "index.php?p=") ? "index.php?p=" : ""); $String .= "discussions/tagged/".rawurlencode($t)."'>$t</a> "; } echo '<span class="DiscussionTags">Tags: '.$String.'</span>'; } ?>

    Directly Before:

    <div class="CommentInfo">

Answers

  • KastangKastang New
    edited December 2011 Answer ✓

    If you copy

    /applications/vanilla/views/discussions/helper_functions.php

    to

    /themes/[YOURTHEME]/views/discussions/helper_functions.php

    you can add the tags string to the discussions by adding:

    if($Discussion->Tags != '') { echo '<span class="DiscussionTags">Tags: '.$Discussion->Tags.'</span>'; }

    directly before

    $Sender->FireEvent('DiscussionMeta');

    located at the bottom of the file.

  • Tried that, but does not display:

    I have:

    if (C('Vanilla.Categories.Use') && $Discussion->CategoryUrlCode != '')
                   echo Wrap(Anchor($Discussion->Category, '/categories/'.rawurlencode($Discussion->CategoryUrlCode), 'Category'));
                if($Discussion->Tags != '') { echo 'Tags: '.$Discussion->Tags.''; }
                $Sender->FireEvent('DiscussionMeta');

    There was an error rendering this rich post.

  • Strike that it does work ! Apologies...

    There was an error rendering this rich post.

  • Would be nice to make them clickable.

    There was an error rendering this rich post.

  • Somehow think i need to use this:

    Anchor(htmlspecialchars($Tag->Name), 'discussions/tagged/'.urlencode($Tag->Name))

    There was an error rendering this rich post.

  • So need to:

    1. wrap each tag in span class.
    2. add url to each tag ( so can be clicked )

    SO far I have.

    if($Discussion->Tags != '') { echo ''.$Discussion->Tags.''; }

    Obviously, the tagWrap wraps all tags, not each tag with css. So need to fix that. Also need to add url to each tag

    There was an error rendering this rich post.

  • KastangKastang New
    edited December 2011 Answer ✓

    Try this:

    if($Discussion->Tags != '') { $Tags = explode(' ',$Discussion->Tags); $String = ""; foreach($Tags as $t) { $String .= "<a href='index.php?p=discussions/tagged/".rawurlencode($t)."'>$t</a> "; } echo '<span class="DiscussionTags">Tags: '.$String.'</span>'; }

    The above is assuming you are NOT using URL Rewriting. If you are, change the $String variable in the foreach loop to:

    $String .= "<a href='discussions/tagged/".rawurlencode($t)."'>$t</a> ";

  • hahah you are good. Cheers. Will get styling, and post screeny soon. Cheers !!!

    There was an error rendering this rich post.

  • For anyone in the future looking to do this; here is a slightly less hackish way that will automatically adjust for rewrite URLs being either on or off:

    `

             if($Discussion->Tags != '') {
                $Tags = explode(' ',$Discussion->Tags);
                $String = "";
                foreach($Tags as $t) {
                    $String .= "<a href='";
                    $String .= (strstr($Discussion->Url, "index.php?p=") ? "index.php?p=" : "");
                    $String .= "discussions/tagged/".rawurlencode($t)."'>$t</a> ";
                }
                echo '<span class="DiscussionTags">Tags: '.$String.'</span>';
            }
    

    `

  • Do you know what the code would be to also add tags to first post in thread ?

    There was an error rendering this rich post.

  • KastangKastang New
    edited December 2011 Answer ✓

    Move:

    /applications/vanilla/views/discussion/helper_functions.php

    To:

    /themes/[YOURTHEME]/views/discussion/helper_functions.php

    Add:

    <? if($Sender->Discussion->Tags != '' && $Type != 'Comment') { $Tags = explode(' ',$Sender->Discussion->Tags); $String = ""; foreach($Tags as $t) { $String .= "<a href='"; $String .= (strstr($Sender->Form->Action, "index.php?p=") ? "index.php?p=" : ""); $String .= "discussions/tagged/".rawurlencode($t)."'>$t</a> "; } echo '<span class="DiscussionTags">Tags: '.$String.'</span>'; } ?>

    Directly Before:

    <div class="CommentInfo">

  • @kastang i will try this first thing in the mornng, thanks mate

    There was an error rendering this rich post.

  • @kastang , works perfectly. Small adjustment to String, and its perfect. Thanks.

    There was an error rendering this rich post.

  • @kastang

    I was looking for this as well. But I don't see <div class="CommentInfo"> in helper_functions.php

    Has it changed recently? Could you help me figure out where to insert this. I'm on Vanilla 2.0.18.3. Sorry I'm not a php developer. Thanks for your help.

Sign In or Register to comment.