I've just started writing plugins on Wordpress and I'm struggling with adding a small button on every post that helps translate the whole post into another language. I tried to get the post's content, then add a button into it and return. But this certainly seems very bad. Can anybody think of a different way of doing this?
And (say) if I successfully place a button on a post, how can I make it performs its 开发者_运维百科function when users click on it?
Thank you.
Adding a button to every post can be done using the appropriate action: for what you want to do see the *edit_post* action (at http://codex.wordpress.org/Plugin_API/Action_Reference). You should be able to add your button's content to the end of the post. Alternatively you might need to modify the theme to add the buttons (if you don't want to modify the post content).
As far as performing its function, if you're familiar with jQuery you can attach an event listener to the button you insert into the post that performs the actual functionality. You can make an ajax callback to your plugin as described here: http://codex.wordpress.org/AJAX_in_Plugins.
精彩评论