Created
May 11, 2016 07:06
-
-
Save daipresents/0971a3ceeeda661e13538304e280afdd to your computer and use it in GitHub Desktop.
楽天ウェブサービスAPI+jQueryでブログにアフィリエイトを簡単自動表示する方法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script type="text/javascript" src="http://www.google.com/jsapi"></script> | |
| <script type="text/javascript">google.load("jquery", "1.5");</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // jquery.rakutenWebService.js | |
| function rakutenWebServiceList(post) | |
| { | |
| var recommendBooks = ''; | |
| jQuery.ajax({ | |
| type: 'GET', | |
| url: 'http://api.rakuten.co.jp/rws/3.0/json', | |
| cache: false, | |
| dataType: 'jsonp', | |
| jsonp: "callBack", | |
| data: { | |
| "developerId": "ここにIDを記述", | |
| "affiliateId": "ここにIDを記述", | |
| "operation": "BooksBookSearch", | |
| "version": "2011-01-27", | |
| "title": post.keyword, | |
| "hits": 10, | |
| "sort": "sales", | |
| }, | |
| success: function(responseData) | |
| { | |
| if (responseData.Body == null){ | |
| recommendBooks = '<!-- Rakuten Widget FROM HERE --><script type="text/javascript">rakuten_design="slide";rakuten_affiliateId="083e725d.9f80cfff.08a38195.ab70278c";rakuten_items="ctsmatch";rakuten_genreId=0;rakuten_size="600x200";rakuten_target="_blank";rakuten_theme="gray";rakuten_border="off";rakuten_auto_mode="on";rakuten_genre_title="off";rakuten_recommend="on";rakuten_ver="20100708";</script><script type="text/javascript" src="http://xml.affiliate.rakuten.co.jp/widget/js/rakuten_widget.js"></script><!-- Rakuten Widget TO HERE -->'; | |
| } else { | |
| $.each(responseData.Body.BooksBookSearch.Items.Item, function(i, item) { | |
| recommendBooks += ( | |
| '<div class="book">' + | |
| '<img src="' + item.mediumImageUrl + '" alt="' + item.title + '"/><br/>' + | |
| '<a href="' + item.affiliateUrl + '">' + item.title + '</a><br/>' + | |
| '<span class="bookInfo">著者:' + item.author + ' (' + item.publisherName + ')</span> ' + | |
| '<span class="bookPrice">' + item.itemPrice + '円(税込)</span></div>' | |
| ); | |
| }); | |
| } | |
| jQuery(post.id).append(recommendBooks); | |
| jQuery(post.id).append('<div class="booksClear"/>'); | |
| }, | |
| complete: function() { | |
| } | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script type="text/javascript" src="<?php bloginfo("url"); ?>/js/jquery.rakutenWebService.js" charset="utf-8"></script> | |
| <script type="text/javascript"> | |
| rakutenWebServiceList({ | |
| id: '#recommendBooks', | |
| keyword: '<?php echo $tag->description; ?>', // $tagを使って関連商品を検索しレコメンド | |
| }); | |
| </script> | |
| <div id="recommendBooks"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment