ThemeShaper Forums » Thematic

[closed]

Removing an Action Hook from a Post Template?

(18 posts)
  • Started 3 years ago by soupking
  • Latest reply from soupking
  • This topic is resolved
  1. soupking
    Member

    Okay, I did the template by category number:

    `
    $post = $wp_query->post;
    if ( in_category('9') ) {include(STYLESHEETPATH . '/singleOranges.php');}
    else {include(STYLESHEETPATH . '/singleOriginal.php');
    }
    '

    Simply deleting the thematic_abovecontent() in the custom post only through the entire container portion to the bottom below everything.

    What's a good way to go about this? Anybody? Should I go the functions.php route or somehow insert DIV tags and styles and somehow make the section display:none.

    Any links or code clips would be wonderful. It's taken me 4 hours to just get this far enough to screw it up. :P

    Posted 3 years ago #
  2. sorry dude, i never understand what you are asking the first time. are you trying to display posts from a particular category is a totally different way than regular posts?

    Posted 3 years ago #
  3. soupking
    Member

    Hehehe, Helga that's fine. I'm so thankful that you (and others) care. :)

    Like for example, I have this flash header as well as sidebar content I wish to alter or remove from blog posts. So I believe I need to setup a PHP condition to do so either by category (which I've been able to trace) or some other means.

    I've figured out how to do this page templates. That's a walk in the park. I just can't seem to find any examples that do it for posts. Many will show you how to re-route post templates, but...then what? You know?

    The thing is I'm building this site for complete luddites as a friendly favor. So I really need all blog posts to automate to one style. No admin form plugin options. I don't need to really have categories involved as this is a basic blog with one blog type. The rest are pages, but I can't have the blog page(s) looking like the index.

    I hope that makes sense and isn't TOO wordy. That's another one of my hang-ups.

    Thanks a bunch for reading! :D

    Posted 3 years ago #
  4. hmmm... i am still not 100% sure i am following, BUT what if you add the flash header and sidebar content conditionally so that it doesn't appear on single posts? i think telling your content specifically where to appear is easier than telling it to appear everywhere and then trying to figure out how to remove the hooks from certain places. (again, this presumes i am following you)

    for example

    function bacon(){
      echo "bacon here!";
    }
    add_action('thematic_abovemainasides','bacon');

    puts "bacon" on every page/post/archive. and while i like bacon, that doesn't sound like what you are going for.

    say you only want to put bacon on the home index page, you'd use conditional logic

    function bacon(){
     if(is_home()){
      echo "bacon here!";
     }
    }
    add_action('thematic_abovemainasides','bacon');

    see the codex for the full rundown on WP conditionals:
    http://codex.wordpress.org/Conditional_Tags

    also you can use the PHP ! operator... which means NOT. so the following would put bacon on every page of your site that ISN'T a single blog post

    function bacon(){
     if(!(is_single())){
      echo "bacon here!";
     }
    }
    add_action('thematic_abovemainasides','bacon');

    hope that all makes sense and i hope it is what you are looking for

    Posted 3 years ago #
  5. AnotherAndrew
    Member

    Soupking, you and I are in the same boat.

    For a custom post template, copy your single.php and rename it to something like single-1.php. "1" being the id of your category.

    Put this in your functions.php

    add_filter('single_template', create_function('$t', 'foreach( (array) get_the_category() as $cat ) { if ( file_exists(TEMPLATEPATH . "/single-{$cat->term_id}.php") ) return TEMPLATEPATH . "/single-{$cat->term_id}.php"; } return $t;' ));

    Now edit the single-1.php to remove or add functions.

    However, for me, I can't some functions to work! Anyone have some additional tips?

    Posted 3 years ago #
  6. @andrew- the above code might not work b/c TEMPLATEPATH is pointing to the Thematic folder. so assuming you've put your file in your child theme folder it'll never find it. maybe trying STYLESHEETPATH will help?

    i still hold that the custom post templates is a pretty easy solution. though it won't do what you are attempting which seems to be to automagically make every post in a particular category use a specific template.

    Posted 3 years ago #
  7. AnotherAndrew
    Member

    You are right it needs to have STYLESHEETPATH to work with child themes.

    // create single.php template files for categories based on id, EX single-10.php
    add_filter('single_template', create_function('$t', 'foreach( (array) get_the_category() as $cat ) { if ( file_exists(STYLESHEETPATH . "/single-{$cat->term_id}.php") ) return STYLESHEETPATH . "/single-{$cat->term_id}.php"; } return $t;' ));

    Posted 3 years ago #
  8. soupking
    Member

    Yes, this is exactly what I'm dealing with but what I don't understand is how to remove something that I don't have a function for in functions.php

    I can only remove what I create as far as my knowledge spans.

    For instance, I want to remove something pre-defined like thematic_abovecontent() or swap out content of the sidebar.

    I don't understand what kind of condition I'm supposed to put together for the removal/swap.

    To break that code down...

    add_filter('single_template', create_function('$t', 'foreach( (array) get_the_category() as $cat ) {

    I understand that I'm adding something and getting post categories within a range...But why?

    if ( file_exists(STYLESHEETPATH . "/single-{$cat->term_id}.php") ) 
    
    return STYLESHEETPATH . "/single-{$cat->term_id}.php"; } return $t;' ));

    ...This looks like it's saying if single-10.php exists then return this page instead of single.php.

    I've gotten that far. I can swap pages.

    I can't swap what's IN the pages or find an example that shows how to do that.

    Do you guys know of any?

    Thanks for reading you guys, great responses! :D

    Posted 3 years ago #
  9. AnotherAndrew
    Member

    "I can't swap what's IN the pages or find an example that shows how to do that."

    Your posts need to have the correct category associated with the other single.php page.

    In the example above, all posts that have the id of 10 will read the single-10.php page.

    You can also use the name of the category in place of the numerical value.

    Does that help?

    Posted 3 years ago #
  10. soupking
    Member

    Kind of, like I found this example:

    <?php
        $post = $wp_query->post;
        if ( in_category('9') ) {include(STYLESHEETPATH . '/singleOranges.php');}
        else {include(STYLESHEETPATH . '/singleOriginal.php');
        }
    ?>

    I get that I can use category types as well as ID numbers. So cool, the page re-routes to "singleOranges.php".

    But then what, you know? I'm currently stuck with a post template I can't remove stuff. I'm reading about filters and hooks and they all sounds the same:

    http://codex.wordpress.org/Function_Reference/add_filter

    Then the codex will give examples with data included except I have no concept what array data or syntax anything is based on. I don't really understand what I'm attempting to remove. Is it a filter or a hook, or both?

    In all, I'd like to the remove action hook/filter 'thematic_abovecontent()' or the div tag within it on my posts. If I knew what conditional syntax to remove something would be, I think I could just re-apply everywhere.

    Even if I swap post templates based on category/ID, I still can't figure out how to customize sections of my new "singleOranges.php".

    I hope that question makes sense. I've never been so lousy at asking questions. lol

    Thanks for responding AnotherAndrew! :)

    Posted 3 years ago #
  11. what ARE you trying to remove exactly? title, meta, content, sidebar, etc? if you can tell us the OUTPUT that you want to get rid of we can help you backtrack to where it is coming from.

    why would you need to remove 'thematic_abovecontent()' ?? it is just an empty hook. unless you have added something to it in your own functions.php it does nothing. think of hooks as a hat rack... they are only there for you to hang your hat on (add functions to).

    if you HAVE put a function on thematic_abovecontent, but DON'T want it to display in this particular category then you need conditional logic on your initial function and NOT to remove the hook in places.

    adding filters is different in that the function is already in place and you are passing it a different variable. i dont have a good analogy for filters and honestly, it took me a while to really understand them myself.

    here is a basic example (bacon-free even)

    function my_excerpt_length($length) {
       return 20;
    }
    add_filter('excerpt_length', 'my_excerpt_length');

    now in the wp_trim_excerpt function in the wp-includes/formatting.php file there is a bit that says

    $excerpt_length = apply_filters('excerpt_length', 55);

    basically this is going to take the value of that you returned above (with the my_excerpt_length function) and that will become the new value of the variable $excerpt_length. if you don't add a filter there it defaults to 55. maybe this one is like WP was playing with a soccer ball, but you passed it a basketball and so now it will play with that.

    Posted 3 years ago #
  12. soupking
    Member

    Hi Helga,

    It's probably best if I just show you. Here's my blog:

    http://axiom-media.com/work/fdb/

    I have a dynamic Flash banner built into the top. However, it re-appears on every blog post.

    Eventually I'd like to customize the sidebar content as well. But for starters, I'd like to just remove the big Flash piece in posts. I don't even really need/have categories.

    That's it. Sorry if I've been really roundabout in my description. I might even be asking the wrong questions if I have the wrong idea about what I'm trying to do.

    Thanks to you and all you guys for your patience and assistance. :)

    Posted 3 years ago #
  13. good call, b/c we've been having a massive disconnect. i don't know how to answer your questions b/c i don't understand what you are trying to do. now i finally understand a little better.

    1. what code are you using to add that banner?

    2. where do you want it to appear vs where DON'T you want it to appear?

    ps- i'm relieved you don't need my help for a YANKEES website

    Posted 3 years ago #
  14. soupking
    Member

    hehehe, nah. I couldn't afford to be a Yankees fan anyway.

    1) Here's the code in functions.php that I'm using to add the Flash banner:

    function flashBanner() { ?>
    <div id="flashContent">
    <object width="625" height="325">
        <param name="movie" value="http://axiom-media.com/work/fdb/wp-content/themes/feelingDodgerBlue/media/Banner_7.swf">
        <embed src="http://axiom-media.com/work/fdb/wp-content/themes/feelingDodgerBlue/media/Banner_7.swf" width="625" height="325">
        </embed>
    </object>
    </div>
    <?php }
    add_action('thematic_abovecontent', 'flashBanner');

    2) The Flash banner is just supposed to be for the index page, NOT on the blog posts.

    ------------------

    If you select any of the imported blog stories all the matching index content appears on it as well. So I'm looking to take remove_action on the Flash banner and soon the sidebar content for posts.

    The thing is I'm not going to be posting threads on this, and I can't rely on my uber-luddite friends to remember to select a drop down selection to keep the layout together.

    So I'm trying to find the right PHP syntax to say, "If this page is a blog post, then remove Flash banner from content_abovecontent OR remove div ID "flashBanner" from content_abovecontent; which ever is the right way to think/study/act.

    That's pretty clear right? I'm hoping I can make some sense at some length.

    Posted 3 years ago #
  15. ok i think we might be getting somewhere.... and more than ever i believe that what you are after is called conditional logic

    if you only want the banner to appear on the home page then

    "show the banner only on the home page" is a better choice of logic than
    "If this page is a blog post, then remove Flash banner from content_abovecontent"

    but if you want to include the banner on every page, category, tag archive, author archive, etc that IS NOT a blog post you could do that w/ the conditional !(is_single())

    to put your banner ONLY on the home page try this:

    function flashBanner() {
    if(is_home()){ //only show the banner on the home index ?>
    <div id="flashContent">
    <object width="625" height="325">
        <param name="movie" value="http://axiom-media.com/work/fdb/wp-content/themes/feelingDodgerBlue/media/Banner_7.swf">
        <embed src="http://axiom-media.com/work/fdb/wp-content/themes/feelingDodgerBlue/media/Banner_7.swf" width="625" height="325">
        </embed>
    </object>
    </div>
    <?php }
    }
    add_action('thematic_abovecontent', 'flashBanner');

    i know you are trying to wrap your head around a lot of things right now but i think you'll get a lot of bang for your buck if you can even sort of understand conditional tags

    http://codex.wordpress.org/Conditional_Tags

    throw the NOT operator ! (the exclamation point) and you suddenly have access to

    is_home() //true if is the home (blog) page

    and

    !(is_home()) //true for every page that is NOT the home (blog) page

    Posted 3 years ago #
  16. soupking
    Member

    Ach! I knew it had to be so simple.

    The thing is I went to that page (among several others) and I never understand what they're talking about. They are so good at giving you examples that make sense if you already know what you're doing. I know that sounds so ignorant, but it happens every time I go there.

    It's hard to give instances without writing a small essay in this reply. However, I'll gladly mention that that Codex page has no HTML tagging in it whatsoever (like many of their pages) so I never have any idea how to connect the two.

    The answer was yours:

    if(is_home()){ //only show the banner on the home index ?>
    <div id="flashContent">
    // insert content desired if the existing page is home
    </div>
    <?php }

    To make it negative insert the ! before the condition parenthesis().

    Until now, I've had no idea how to combine PHP with HTML for anything other than global ADD / REMOVE functionality. Now I understand that a simple PHP condition written in front of the tagging in the called function was what was needed.

    Thank you!! Thank you!! Thank you!! Thank you Helga!!! :D

    So stoked, I couldn't find the answer to find out how to control HTML DIV tagging conditionally. I'm actually going to get this blog finished after all.

    Total awesomeness, thanks again. I'm sure I'll be back with more terribly-formed questions. :P

    Posted 3 years ago #
  17. well i'm glad we got that figured out. i've been very confused about just wth you were doing and why it seemed more complicated than anything i've done! it is definitely a pain in the beginning to try to learn everything that you seem to need to even be able to ask good questions. a link is worth a thousand words, huh?

    but it isn't good to hear that the codex is so wildly confusing b/c i feel like i send people to the conditional logic page 3x per week. hell just tonight i've posted that link 3 times. conditional logic is the missing link that many people come here looking for.

    how do I put Y on only Z page?
    how do I put A on every page except B?

    always, always comes down to conditional logic... so that's vital to learn if you want to do anything cool

    Posted 3 years ago #
  18. soupking
    Member

    OMG, tell me about it. As a Flash designer/developer I understand conditional as well as case logic, arrays, all that. However, the codex assumes you understand the syntax that goes along with combining PHP with HTML tagging.

    Which...I haven't. I can't find the page that shows that anywhere. I've gone through and through the codex over and over. Heh, and then people just tell you to go back. I'm sure it's useful if you get the basics, but I think one thing that the Codex misses is the difference between learning API vocabulary and practical syntax. Most of the demos I've used have been pulled by posts made by Ian. Because if you're new to PHP, you've not just going to know how to put combine code together without popping up a ton of errors.

    This whole time I've been stuck not knowing how to do that. Even worse, not knowing how to simplify the question. You're absolutely right. If you can't put on/off switches in your blog, you're really stuck.

    Again, thanks a bunch. You've been a HUGE help. Our Dodger camp is grateful even though they have no idea what I'm doing.

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.