简体   繁体   English

Wordpress-如何在Wordpress的帖子中添加按钮并使之起作用?

[英]Wordpress - How to add a button into a Wordpress' post and make it work?

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. 我刚刚开始在Wordpress上编写插件,并且在每个帖子上添加一个小按钮以帮助将整个帖子翻译成另一种语言感到很苦恼。 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 ). 可以使用适当的操作为每个帖子添加按钮:有关您要执行的操作,请参见* edit_post *操作(位于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. 就执行其功能而言,如果您熟悉jQuery,则可以将事件侦听器附加到插入到执行实际功能的帖子中的按钮上。 You can make an ajax callback to your plugin as described here: http://codex.wordpress.org/AJAX_in_Plugins . 您可以按照以下说明对插件进行ajax回调: http : //codex.wordpress.org/AJAX_in_Plugins

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM