ThemeShaper Forums » Thematic

[closed]

actions vs hooks question

(12 posts)
  • Started 3 years ago by rj
  • Latest reply from helgatheviking
  • This topic is not resolved
  1. rj
    Member

    I am sure there is a logical answer to this but I don't see it explained anywhere. Bear with the newb here.

    What are the differences between action hooks and filter hooks?
    Thanks

    Posted 3 years ago #
  2. an action hook is like a coat hook. it is a place where you can hang any kind of coat.

    a filter hook is more like a ball pit. with the filter you can change the color/type of the ball in the pit? yeah, i still haven't perfected my filter metaphor. but filters let you pass in different variables.

    Posted 3 years ago #
  3. kwight
    Member

    If you stick with the popular "car" metaphors used in, well, pretty much everything...

    Imagine your website is a parking lot, with the different elements of your site being cars. Action hooks add or remove cars, while filters are used to somehow change an existing car (say, from blue to red).

    Action hooks add or remove elements, filter hooks change how elements are presented (I say "presented", because filters don't change the actual contents in the database, they just change the contents into a different form for presentation).

    In Thematic, you would use an action hook to add a featured posts section below the header:

    function kwight_add_featured_posts() { ?>
        <div id="featured">
            <!-- featured posts code  -->
        </div><!-- end featured -->
    <?php }
    
    add_action('thematic_belowheader','kwight_add_featured_posts');

    However, you would use a filter hook to change the existing "read more" text:

    function kwight_change_more_text($content) {
        $content = 'Continue reading >';
        return $content;
    }
    add_filter('more_text', 'kwight_change_more_text');

    I find filter hooks a little more difficult to wrap your head around, as they can do so much and be used in so many different ways; they can not only change elements, but add to, replace and completely remove them.

    This link might also help:

    http://a.parsons.edu/~zeravivm/s10/osd/admin/04/06/lets-be-clear-on-this-the-difference-between-filters-and-hooks/

    Um... something like that.

    Posted 3 years ago #
  4. Kwight that's a good description. Sorry HTV I have no clue what a ball pit is, must be Canadian :)

    Posted 3 years ago #
  5. well i did warn you that i hadn't worked out my metaphor yet. but seriously, no ball pits in canada?

    http://www.youtube.com/watch?v=CDNCfMmC0SQ

    that is a shame. or a dommage depending on which part of canada you are from.

    i do like the parking lot metaphor. i will probably steal it the next time someone asks this question...

    Posted 3 years ago #
  6. Oh so that's a ball pit! I never knew what they were called. but I remember the Simpsons episode "the children look unhappy, add more balls" For some reason I thought YOU were Canadian, I have no idea why. I'm in San Francisco. merci quand même.

    Posted 3 years ago #
  7. yup! ball pit is an uber-creative name for a pit, full of balls. nope, american all the way here, but located all over... (2 years in france explains the attempts at français). which is better than my Polish. just got back from 3 months in Poland and all i can really say is pierogies please.

    Posted 3 years ago #
  8. kwight
    Member

    Funny, I didn't get the "ball pit" reference either (and I am Canadian). I guess it's just one of those things that exists, but we've never really had to call it by name (like a tine - I'll let everyone look it up :)

    Posted 3 years ago #
  9. If I'm ever smart enough to come up with a really good theme, I'll name it BallPitPierogiesTine in honor of y'all

    Posted 3 years ago #
  10. ok, so i think its clear. ball pit = bad metaphor.

    Posted 3 years ago #
  11. I think no knowledge of ball pits = bad childhood :\

    Posted 2 years ago #
  12. @siguy for the win! i concur! i've been meaning to work up some graphics for a parking lot metaphor, but i'm always swamped.

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.