var x = 0; if (window.location.search.indexOf('tumblrpage=') > -1) { var url = $(location).attr('href'); url = url.split('='); x = url[1] * 5 - 5; currentpage = url[1]; } else { currentpage = 1; } repeatAjax(); function repeatAjax() { $.ajax({ url: '<?php echo get_bloginfo("stylesheet_directory"); ?>/tumblr/api.php', type: 'post', dataType: 'json', data: { 'tag': '<?php echo $liveblog_tag; ?>', 'offset': x }, success: function (posts) { var postings = posts.response.posts; console.log(postings); var text = ''; for (var i in postings) { var p = postings[i]; text += '<li>'; var taglength = p.tags.length; var author = '' var authorfound = 0; var title = ''; var social_title = ''; var social_handle = ''; var titlefound = 0; for (var i = 0; i < taglength; i++) { if (p.tags[i].search(/author/i) != -1) { author = p.tags[i].replace('author:', ''); authorfound = 1; } else if ((p.tags[i].search(/author/i) == -1 && (authorfound != 1))) { author = 'Guest Poster'; authorfound = 0; } if (p.tags[i].search(/title/i) != -1) { title = p.tags[i].replace('title:', ''); titlefound = 1; } else if ((p.tags[i].search(/title/i) == -1 && (titlefound != 1))) { title = ''; titlefound = 0; } } if (p.type == 'photo') { text += '<!-- photo --><h3>' + title + '</h3>'; if (p.photos.length > 1) { text += '<div class="liveblog_gallery">'; for (var x in p.photos) { text += '<figure><a href="' + p.photos[x].original_size.url + '" class="fancybox" rel="gallery-' + p.reblog_key + '"><img src="' + p.photos[x].alt_sizes[1].url + '"></a>'; } text += '<figcaption><p>' + p.caption + '</p></figcaption></figure></div>'; } else { text += '<figure><img src="' + p.photos[0].alt_sizes[1].url + '"><figcaption><p>' + p.caption + '</p></figcaption></figure>'; } } else if (p.type == 'text') { text += '<!-- text --><h3>' + p.title + '</h3>' + p.body; } else if (p.type == 'video') { if (p.video_type == 'youtube') { text += '<!-- youtube video --><h3>' + title + '</h3><div class="video-container">' + p.player[2].embed_code + '</div>' + p.caption; } else { text += '<!-- video --><h3>' + title + '</h3><iframe width="700" height="394" frameborder="0" webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen="" data-height="394" data-width="700" data-can-resize="" data-can-gutter="" scrolling="no" class="embed_iframe tumblr_video_iframe" style="display: block; background-color: transparent; overflow: hidden; width: 100%; height: 394px;" src="https://www.tumblr.com/video/<?php echo $liveblog_tumblr_url; ?>/' + p.id + '/700/"></iframe>'; } } else if (p.type == 'quote') { text += '<!-- quote --><blockquote><p>“' + p.text + '”</p><cite>— ' + p.source + '</cite></blockquote>'; } else if (p.type == 'link') { if (!p.excerpt) { var excerpt = ''; } else { var excerpt = '<p>' + p.excerpt + '</p>'; } if (!p.link_image) { var link_image = ''; } else { var link_image = '<a href="' + p.url + '" target="_blank"><img src="' + p.link_image + '"></a>'; } if (p.publisher == 'instagram.com') { social_title = p.title.split(':'); social_handle = p.title.split(' '); text += '<!-- instagram link --><figure>' + link_image + '<figcaption><p>' + p.excerpt + '<br>— <a href="' + p.url + '" target="_blank">' + social_title[0] + '</a></p></figcaption></figure>'; } else if (p.publisher == 'twitter.com') { social_title = p.title.split(' on '); social_handle = p.url.split('/'); if (p.excerpt != null) { var excerpt = p.excerpt.replace(/(https?:\/\/[^\s]+)/g, ""); } text += '<!-- twitter link --><blockquote><p>' + excerpt + '</p><cite>— <a href="' + p.url + '" target="_blank">' + p.title + '</a></cite></blockquote>'; } else { if (!p.link_image) { text += '<!-- link --><h3><a href="' + p.url + '" target="_blank">' + p.title + ' »</a></h3>' + excerpt + p.description; } else { text += '<!-- link --><figure>' + link_image + '<figcaption><h3><a href="' + p.url + '" target="_blank">' + p.title + ' »</a></h3>' + excerpt + p.description + '</figcaption></figure>'; } } } var dts = new Date(p.timestamp * 1000); var n = dts.toLocaleTimeString(); var p = dts.toLocaleDateString(); text += '<div class="liveblog_timestamp">Posted by ' + author + ' on ' + p + ' @ ' + n + '</div>'; text += '</li>'; } $('ul.liveblog_entries').html(text); var result = 0; result = posts.response.total_posts / 5; if (result <= 1) { $('.liveblog_nav').remove(); } else { $('.liveblog_nav_pages').nextAll().remove(); var nav = ''; if (currentpage != 1) { nav += '<div class="navright"><a href="?tumblrpage=' + (+currentpage - 1) + '">Newer »</a></div>'; } if (currentpage != Math.ceil(result)) { nav += '<div class="navleft"><a href="?tumblrpage=' + (+currentpage + 1) + '">« Older</a></div>'; } } $('.liveblog_nav').html(nav); }, complete: function () { setTimeout(repeatAjax, 300000); // After completion of request, time to redo it after 5 minutes (in milliseconds) } }); }
<ul class="liveblog_entries"></ul> <div class="liveblog_nav"></div>