ThemeShaper Forums » Thematic

[closed]

Hook PHP script above post/page footer to hook Addtoany

(13 posts)
  • Started 4 years ago by wprunner
  • Latest reply from helgatheviking
  • This topic is resolved
  1. wprunner
    Member

    Hello,

    The Addtoany and the "Improve Include Page" plugins conflict with each other that caused the Addtonay plugin to add social media bar at different places where it encounters the include code.

    What I intend to do is disable all automatic hooks of the plugin and hardcode the PHP script of it above the post and page templates.

    <?php if( function_exists('ADDTOANY_SHARE_SAVE_KIT') ) { ADDTOANY_SHARE_SAVE_KIT(); } ?>

    I read this:
    http://themeshaper.com/custom-wordpress-hooks-filters-thematic-06/

    but wasn't able to get the results I want.

    I coded this:

    function childtheme_postfooter() {
    
    <?php if( function_exists('ADDTOANY_SHARE_SAVE_KIT') ) { ADDTOANY_SHARE_SAVE_KIT(); } ?>
    
    }
    add_filter ('thematic_postfooter', 'childtheme_postfooter');

    in functions.php

    but this completely redefined the footer and showed the social media bar (the plugin hook) only.

    What I want is just to add the PHP hook over my current post footer.

    Also, how to hook it to pages?

    Thanks in advance.

    Posted 4 years ago #
  2. ahh, If i'm thinking right, then this is something i recently learned the hard way. When applying a filter, you are completely replacing the original function. So, in order to use your new stuff, along with the original postfooter stuff, you gotta add the whole kit-n-kaboodle to your filter, not just your addition. Gotta dig the original postfooter out of /thematic/library/extensions/content_extensions.php and use that as the base for your filter.

    As for pages, if you just want the thing at the top of the content, you could us an add_action to stick it either in the_content, or perhaps thematic_belowheader would be a better choice depending on your theme...if you want it at the bottom of pages...hmm...i'm drawing a blank on that....someone help me out here.

    Posted 4 years ago #
  3. wprunner
    Member

    for the post, that's right. But I want to get the code of what was originally written, it must be put somewhere. If I get that code, I would put it as well in the childtheme_postfooter() with my addon code above it.

    for the page, I got a solution for it, you get the page template, page.php, look for the_content(); . Type your code below it, and you will get that right.

    This unfortunately is not useful in the single post template, single.php. As it contains thematic_singlepost(); which contains the entire post from title to post footer. If you put it below it, the post footer will appear above my addon code. And this is not what I want.

    Now, can somebody tell me, where does the original post footer code come from ? If I can just find it, I would copy it into my childtheme_postfooter() filter and add my addon code above it.

    Posted 4 years ago #
  4. "Gotta dig the original postfooter out of /thematic/library/extensions/content_extensions.php"

    Posted 4 years ago #
  5. you might be able to :

    add_action('thematic_postfooter', 'childtheme_postfooter');

    that might add your function to the hook. tarpontech is right that just add_filtering the way you have will overwrite everything in the normal thematic_postfooter(). you can use add_filter but you have to maintain/pass $postfooter

    function childtheme_postfooter($postfooter) {
    	if( function_exists('ADDTOANY_SHARE_SAVE_KIT') ) {
    		$child_postfooter = $postfooter . ADDTOANY_SHARE_SAVE_KIT();
    		}
    return $child_postfooter;
    
    }
    add_filter ('thematic_postfooter', 'childtheme_postfooter');

    this will tack your function on to the end of the postfooter.

    thematic_postfooter() is defined in the content-extensions.php file. if you are using a new version of thematic you can use childtheme_override_postfooter() w/o filtering/removing/adding/whatever. but i think the above filter will work. you might need conditional logic as what i've got there will indiscriminately attach your function to every postfooter throughout the site.

    Posted 4 years ago #
  6. wprunner
    Member

    Helga you are my hero.

    This is exactly what I was looking for, the ability to attach my code to what is already generated. But actually, the Addtoany bar showed up above the original post footer, this is actually what I want.

    However, I just fixed a problem with your code for when the function does not exist (for instance, if the plugin is deactivated) and made it return the original post footer in such case. Also, removed the $child_postfooter variable for simplicity.

    function childtheme_postfooter($postfooter) {
    	if( function_exists('ADDTOANY_SHARE_SAVE_KIT') ) {
    		return ($postfooter . ADDTOANY_SHARE_SAVE_KIT());
    		}
    	else
    	return $postfooter;
    }
    add_filter ('thematic_postfooter', 'childtheme_postfooter');

    Thank you :)

    Posted 4 years ago #
  7. wprunner
    Member

    One more fix,

    Actually, the ADDTOANY_SHARE_SAVE_KIT() does not return anything. It interacts directly with the display. So, although it showed up correctly, it didn't really concatenate with $postfooter. For that reason, no matter where you put the ADDTOANY_SHARE_SAVE_KIT() in the return, it is just run and will display on top.

    With my new fix, we are just going to interact directly with the display without returning anything.

    function childtheme_postfooter($postfooter) {
    	if( function_exists('ADDTOANY_SHARE_SAVE_KIT') ) {
    		ADDTOANY_SHARE_SAVE_KIT();
    		echo("<br /><br />");
    		}
    	echo ($postfooter);
    }
    add_filter ('thematic_postfooter', 'childtheme_postfooter');

    Now you can control exactly where things are going to display,

    cheers :)

    Posted 4 years ago #
  8. I have posted this elsewhere but realise this thread is probably the right place.

    I would like to put addtoany in entry-utility. Specifically, after postfooter_posttags and before postfooter_postcomments. I have tried various things but I really don't understand php, and copy-paste didn't work this time. Please help me insert this into the right place.

    This is the relevant section of my functions.php file:

    // Custom postfooter
    
    function my_postfooter() {
        global $id, $post;
    
        if ($post->post_type == 'page' && current_user_can('edit_posts')) { /* For logged-in "page" search results */
            $postfooter = '<div class="entry-utility">' . thematic_postfooter_posteditlink();
            $postfooter .= "</div><!-- .entry-utility -->\n";
        } elseif ($post->post_type == 'page') { /* For logged-out "page" search results */
            $postfooter = '';
        } else {
            if (is_single()) {
                $postfooter = '<div class="entry-utility">' . thematic_postmeta_entrydate() . thematic_postfooter_postcategory() . thematic_postfooter_posttags() .  thematic_postfooter_postconnect();
            } else {
                $postfooter = '<div class="entry-utility">' . thematic_postmeta_entrydate() . thematic_postfooter_posttags() . thematic_postfooter_postcomments() ;
            }
            $postfooter .= "</div><!-- .entry-utility -->\n";
        }
    
        return $postfooter;
    } // end my_postfooter
    
    add_filter('thematic_postfooter','my_postfooter');
    Posted 3 years ago #
  9. timothyd
    Member

    I am also trying to place the add to any share plugin in my entry utility. Ideas? I don't like it at the bottom of posts because I simply think it would look better if it were in line with my tags, comments etc. Please help!

    Posted 3 years ago #
  10. i have come a long way in my year since posting my original response... wherein my answer was incorrect.

    unless this plugin offers a function (or a parameter for the ADDTOANY_SHARE_SAVE_KIT() function) that "returns" a value in lieu of "echoing" a value, you cannot add this to the entry-utility via filter.

    you're lucky i seem to have too much time on my hands as it turns out that addtoany does have a return parameter. ;)

    function childtheme_postfooter($postfooter) {
    	if( function_exists('ADDTOANY_SHARE_SAVE_KIT') ) {
    		$postfooter = $postfooter . ADDTOANY_SHARE_SAVE_KIT(array($output_later=TRUE));
    	}
    	return $postfooter;
    }
    add_filter ('thematic_postfooter', 'childtheme_postfooter');

    this doesn't get it INSIDE post-utility however.... might need to hit another filter OR use an override

    Posted 3 years ago #
  11. timothyd
    Member

    I actually placed it where I wanted by minimizing the width of the entry utility, changing clear:both to left, and changing the width of the Add to Any and floating it left. I can't seem to get a handle on these functions, hooks, etc. Probably a backwards way to go about it, but I find solace in CSS.

    Posted 3 years ago #
  12. timothyd
    Member

    *floating it right I meant.

    Posted 3 years ago #
  13. have you read my introduction to primers and filters?
    http://forums.themeshaper.com/topic/need-help-understanding-actions-vs-filters-and-changing-post-meta-and-utility#post-22638

    like i said before, to get it INSIDE of entry-utility, i think you'll need to copy the thematic_postfooter() function completely to your functions.php and rename it childtheme_override_postfooter() and add

    ADDTOANY_SHARE_SAVE_KIT(array($output_later=TRUE))

    somewhere in there

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.