1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[Docs] Designing around Plugin Hooks

Discussion in 'Design and Layout' started by Nick, Sep 1, 2009.

  1. Nick

    Nick Well-Known Member

    One of the difficulties with designing a theme is knowing what to do with all the plugin hooks in a template.

    For example, imagine a typical post from the Submit plugin:

    What you've got

    AVATAR - TITLE
    AUTHOR - DATE - CATEGORY
    DESCRIPTION
    TAGS - COMMENTS - FLAG IT!

    If you delved into the template itself, you'll see you've got something like:

    HOOK - TITLE
    AUTHOR - DATE - HOOK
    DESCRIPTION
    HOOK

    What you want

    Let's say you wanted to move the tags to the top, next to the category, like this:

    AVATAR - TITLE
    AUTHOR - DATE - CATEGORY - TAGS
    DESCRIPTION
    COMMENTS - FLAG IT!

    How you do it

    To do that, you need to understand the plugin hook itself. Let's take a look:

    PHP:
    <?php $h->pluginHook('sb_base_show_post_extra_fields'); ?>
    The pluginHook function takes the following parameters:

    (1) $hook = "";
    (2) $folder = "";
    (3) $parameters = array();
    (4)
    $exclude = array();

    (1) is the name of the plugin hook.
    (2) is if you want to specify which plugin to use. In most cases, this will be blank so all plugins with the same hook will run.
    (3) an array of additional arguments to pass to each function at that hook.

    (4) an array of plugins you don't want to be included.

    So, if you want to show only the tags, you can do this:

    PHP:
    <?php $h->pluginHook('sb_base_show_post_extra_fields''tags'); ?>
    And to exclude tags from the original plugin hook (which you still need to show categories and the alert flag), do this:

    PHP:
    <?php $h->pluginHook('sb_base_show_post_extra_fields''', array(), array('tags')); ?>
    If you want to exclude more than one plugin, just list them in the last array, like this:

    Code:
    array('tags', 'categories', 'plugin3, 'plugin4')
    Summary

    The pluginHook, although not pretty, gives you enough flexibility to completely redesign your theme without breaking things if you choose to add more plugins later on. For a more in-depth look at plugin hooks, read Working with Plugin Hooks.
     
    Last edited: Jan 7, 2010
  2. JonH

    JonH Admin & Design

    Going by your tutorial, I moved the Gravatar to another spot in the template. I just want to make sure a future plugin doesn't follow it!

    I kept the Gravatar plugin from using the default hook by using your example by changing
    PHP:
    <?php $h->pluginHook('sb_base_show_post_pre_title'); ?>
    to:
    PHP:
    <?php $->pluginHook('sb_base_show_post_pre_title''', array(), array('gravatar')); ?>
    and used this where I wanted the Gravatar to appear:
    PHP:
    <?php $h->pluginHook('sb_base_show_post_pre_title''gravatar'); ?>
    It's works fine, I just want make sure this is this pretty much the standard way. :D

    [Yep, that's the way! Nick]
     
    Last edited by a moderator: Jan 7, 2010

Share This Page