likecoin-wordpress
likecoin-wordpress copied to clipboard
Add Widget for likebutton
@john970473 We can continue the discussion here
Someone asked me how to add LikeCoin to the widget. I have tried to add the shortcode on the text widget but I failed because "likecoin_add_likebutton()" is just for posts or pages. Therefore, we could change the function and add the button to the widget.
At this moment, I could only add Javascript to the widget, but the style of the button looks not so good. You can see the widget of my blog : https://www.johntool.com. I think the button is too small, and I have to split url and add to link.
I think we can refactor a bit and let likecoin_add_likebutton()
accept a $post
or $likerId
.
Then from inside a widget we can use get_queried_object to get the $post
id/object.
For cases other than a post, we can use the site LikerId ($option[ LC_OPTION_SITE_LIKECOIN_USER ]
) if it exists, and probably just hide the widget if it is not.
Did I get your idea right?
I don't think that we need to hide the widget. Maybe someone would like to add the like button on the widget only instead of the post. We just need to link the current url to the like button. Besides, we have two solutions.
- Add a draggable widget of LikeCoin.
- Enable the shortcode to be used on the widget.
Currently to embed a likebutton, we need 1. the author's liker ID and 2. the url of the article/page.
For the liker id part, we need the $post
object to get the post author, then try to get liker ID from user meta data; or if a site liker ID exists and is enabled, we should use that.
For the url part, we can use get_queried_object()
if we are in a widget.
However, if there exist no liker ID from neither the post author or site meta, we won't know whose like button should be displayed. Therefore we need to show either an error, a default message telling author to connect liker ID, or hide the widget.
Maybe showing an error message is a good idea ! I think this idea sounds great~
@john970473 Would be nice if you can help with this feature Just open a PR, or a draft one if you are not sure about anything Thanks a lot