Please upgrade here. These earlier versions are no longer being updated and have security issues.

Filter category by Prefix

This discussion is related to the Prefix Discussion addon.

Hi!
First, thank you for your plugin! I appreciate!
I want to know if it's possible to filter categories by Prefix. I mean, you browse a category, on top you have a list of tags, with a link that go to the "same" page, but only with discussions with that Prefix?
I know Tagging plugin kind of do that, with tags, but not restricted to a category.
(I use Vanilla version 2.1.11)

I could create a new plugin, but I'm not familiar with the creation of a plugin. So, is there any suggestion?

Comments

  • hgtonighthgtonight ∞ · New Moderator
    edited June 2015

    Yes, but it will require some plugin development. This plugin adds a prefix column so it should be relatively easy to filter on the model.

    I would look at the QnA or Tagging plugin as an example of how they filter the model for their custom views.

    EDIT - http://docs.vanillaforums.com/developers/plugins/quickstart/

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Well, yes: create a plugin... ;)

    You would need a custom plugin for that. Either you try it yourself or you pay someone for it. If you try to do it yourself, I'll support you, but I guess I will not implement it for you


  • IntellIntell New
    edited June 2015

    Okay, I did start doing something based on Tag plugin for the filter page.
    I successfully made a plugin with a page where there is all the posts for one Prefix, not by category yet.
    I don't understand yet how to manage the URL. Now its
    /discussions/prefix?Page={page}&Prefix={prefix}
    , I would prefer something like
    /discussions/{categoryUrl}/{prefix}/{page} (For filtering based on a category)
    and
    /discussions/all/{prefix}/{page} (For filtering all forums messages)
    There is these lines (still from Tags):

    if (urlencode($Prefix) == $Prefix) {
             $Sender->CanonicalUrl(Url(ConcatSep('/', "/discussions/prefix/$UrlPrefix", PageNumber($Offset, $Limit, TRUE)), TRUE));
          } else {
             $Sender->CanonicalUrl(Url(ConcatSep('/', 'discussions/prefix', PageNumber($Offset, $Limit, TRUE)).'?Prefix='.$UrlPrefix, TRUE));
          }
    

    And, after being able to filter by category, how can I add link on top (under the title) of each page of a category display?

    R_Jhgtonight
  • I successfully finished the page, thank you for your hint.
    So now, is there a way to add the tag list on the categories pages? ( /categories/{category} )
    I would like to have it under the description, so is there a way?

    R_Jhgtonight
  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Great! I'm glad you came that far! Try taking a look at the plugin Eventi: it will be a great help if you start developing your own plugins. In this case, it would help you find CategoriesController_BeforeNewDiscussionButton_Handler

    public function categoriesController_beforeNewDiscussionButton_handler ($sender) {
        // get prefixes from config
        $prefixes = array_filter(
            explode(
                Gdn::config('Plugins.PrefixDiscussion.ListSeparator', ';'),
                Gdn::config(
                    'Plugins.PrefixDiscussion.Prefixes',
                    'Question;Solved'
                )
            )
        );
        array_unshift($prefixes, t('PrefixDiscussion.None', '-'));
        $prefixes = array_combine($prefixes, $prefixes);
    
        // output a list of prefixes as links
        $request = Gdn::Request();
        echo '<ul class="PrefixList">';
        foreach ($prefixes as $prefix) {
            echo '<li>', anchor($prefix, $request->SelfUrl.'/'.$prefix), '</li>';
        }
        echo '</ul>';
    }
    

    I haven't tested that, but it should be quite close to what you need (except for the styling)


    hgtonight
  • It works fine, but how do you prevent it from appearing on the side menu? I suppose I add a if condition that valid we aren't in a module, I'm not really sure.

    R_J
  • Oh, got an idea, I can just hide it in css.

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Seems like I've told you an event that is fired from the NewDiscussion module :(
    And to be honest: I do not know a way to tell if the module is in Panel or in Content, but since the New Discussion button is above and below the discussions, it wouldn't work anyway.

    In Vanilla 2.2 there seems to be a "categoriesController_afterPageTitle_handler" event but I wouldn't know what to advise for Vanilla 2.1 except for another place, but it sucks not to be able to put it where you like.

    If no one else has a better idea, you could override the view in your theme and simply add the fireEvent line where you need it.


  • hgtonighthgtonight ∞ · New Moderator

    @R_J said:
    Seems like I've told you an event that is fired from the NewDiscussion module :(
    And to be honest: I do not know a way to tell if the module is in Panel or in Content...

    Most hooks have the asset name for modules set, so $asset = val('AssetName', $sender->EventArguments, NULL);

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

    R_J
  • Works fine, now it doesn't show up on panel! Thank you both for your help. ;)

    R_J
  • rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    @Intell said:
    Hi!
    First, thank you for your plugin! I appreciate!
    I want to know if it's possible to filter categories by Prefix. I mean, you browse a category, on top you have a list of tags, with a link that go to the "same" page, but only with discussions with that Prefix?
    I know Tagging plugin kind of do that, with tags, but not restricted to a category.
    (I use Vanilla version 2.1.11)

    I could create a new plugin, but I'm not familiar with the creation of a plugin. So, is there any suggestion?

    The answer is yes, it is possible. Take a look at the Filterbyprefix plugin.

Sign In or Register to comment.