{"id":1165,"date":"2009-08-11T06:55:14","date_gmt":"2009-08-11T04:55:14","guid":{"rendered":"http:\/\/code.openark.org\/blog\/?p=1165"},"modified":"2009-08-11T14:46:08","modified_gmt":"2009-08-11T12:46:08","slug":"vote-for-me-how-to-embed-in-wordpress","status":"publish","type":"post","link":"https:\/\/code.openark.org\/blog\/mysql\/vote-for-me-how-to-embed-in-wordpress","title":{"rendered":"&#8220;Vote for me&#8230;&#8221; how to embed in WordPress"},"content":{"rendered":"<p>[<strong>Clarification<\/strong>: <em>I&#8217;m not actually asking you to vote for me :D, the title just follows a previous post<\/em>]<\/p>\n<p>Diego Medina has <a href=\"http:\/\/fmpwizard.blogspot.com\/2009\/08\/vote-for-me-widget-for-your-blog.html?showComment=1249965433072#c6520785617042085252\">published<\/a> a JavaScript code that can be embedded in your blog posts, and which allows for voting on Planet MySQL from within your blog.<\/p>\n<p>Shared below is how to set this up for WordPress users. This is <em>not<\/em> a WordPress plugin, mind you. You&#8217;ll need to manually edit the WordPress template files (can be done from the <strong>Dashboard<\/strong>-&gt;<strong>Appearance<\/strong>-&gt;<strong>Editor<\/strong>-&gt;<strong>Single post<\/strong>).<\/p>\n<p>The page you&#8217;re likely to edit is <strong>single.php<\/strong>, but depending on your template this can change. The explanation below assumes a single post page. This can also be worked out for your blog&#8217;s home page, which lists several entries.<\/p>\n<p>Since there is no point in presenting the Planet MySQL voting widget for entries which do not relate to MySQL, the code verifies that the post is in the <strong>&#8216;MySQL&#8217;<\/strong> category. You need to change this if your categorization differs. Mind that the category&#8217;s name is case sensitive.<!--more--><\/p>\n<blockquote>\n<pre>&lt;?php if ( in_category( 'MySQL' )) { ?&gt;\r\n        &lt;script language=\"JavaScript\"&gt;&lt;!--\r\n        var planet = \"http:\/\/planet.mysql.com\/entry\/vote\/?apivote=1&amp;\";\r\n        var lk=encodeURIComponent(document.location);\r\n        var thumb_up=\"&lt;img src=\\\"http:\/\/planet.mysql.com\/images\/thumbs_up_blue.jpg\\\" border=\\\"0\\\" \/&gt;\";\r\n        var thumb_down=\"&lt;img src=\\\"http:\/\/planet.mysql.com\/images\/thumbs_down_blue.jpg\\\" border=\\\"0\\\" \/&gt;\";\r\n        document.write('Vote on the &lt;br \/&gt;&lt;a href=\\\"http:\/\/planet.mysql.com\/\\\" &gt;Planet MySQL&lt;\/a&gt;&lt;br \/&gt;');\r\n        document.write('&lt;a title=\\\"Vote me Up on the Planet MySQL\\\" href=\\\"' + planet + 'vote=1&amp;url=' + lk  +  '\\\"&gt;' + thumb_up + '&lt;\/a&gt;');\r\n        document.write('&amp;nbsp;');\r\n        document.write('&lt;a title=\\\"Vote me Down on the Planet MySQL\\\" href=\\\"' + planet + 'vote=-1&amp;url=' + lk  +  '\\\"&gt;' + thumb_down + '&lt;\/a&gt;');\r\n        \/\/ --&gt;&lt;\/script&gt;\r\n&lt;?php } ?&gt;<\/pre>\n<\/blockquote>\n<p>The <strong>in_category( &#8216;MySQL&#8217; )<\/strong> function determines if the current post is relevant. You may also choose to show the widget based on tags, in which case you&#8217;ll need to use <strong>get_the_tags()<\/strong>, and verify your MySQL tag is in the resulting array.<\/p>\n<p>I chose to embed this just before the comments area.<\/p>\n<p>Good luck<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Clarification: I&#8217;m not actually asking you to vote for me :D, the title just follows a previous post] Diego Medina has published a JavaScript code that can be embedded in your blog posts, and which allows for voting on Planet MySQL from within your blog. Shared below is how to set this up for WordPress [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[5],"tags":[42],"class_list":["post-1165","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-planet"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2bZZp-iN","_links":{"self":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/1165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/comments?post=1165"}],"version-history":[{"count":7,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/1165\/revisions"}],"predecessor-version":[{"id":1168,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/1165\/revisions\/1168"}],"wp:attachment":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/media?parent=1165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/categories?post=1165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/tags?post=1165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}