Getting Thumbnail from RSS Feed and Display in Listview - php

i need some help with my RSS Feed Reader Script...
I want Thumbnails in my Listview taken from Rss Feeds Thumbnail
"content": [
{
"medium": "image",
"url": "http://www......de/wp-content/uploads/2010/11/sgroth_web.jpg",
"title": {
"type": "html",
"content": "sgroth_web"
},
"description": {
"type": "html",
"content": "contenthere 4."
},
"thumbnail": {
"url": "http://www.sdddd.de/wp-content/uploads/2010/11/sgroth_web-150x150.jpg"
}
have a look what i mean:
Preview
First comes the Thumbnail and then the Title of the Rss Feed..
This Code is Jquery and PHP...
and here is my Code to Display RssFeeds in JS:
$(function(){
getOnlineFeed('http://salzstreuner.de/category/aktuelle_ausgabe/feed');
});
/* functions */
var listEntries = function(json) {
if (!json.responseData.feed.entries) return false;
$('#widgetTitle').text(json.responseData.feed.title);
var articleLength =json.responseData.feed.entries.length;
articleLength = (articleLength > maxLength) ? maxLength : articleLength;
for (var i = 1; i <= articleLength ; i++) {
var entry = json.responseData.feed.entries[i-1];
$('#link' + i).text(entry.title);
$('#articleHeader' + i).text(entry.title);
$('#openButton' + i).attr('href', entry.link);
$('#articleContent' + i).append(entry.content);
$('#articleImage').append('<img src="' + entry.thumbnail + '">');
}
$('#article1 .prevButton').remove();
$('#article' + articleLength + ' .nextButton').remove();
if (articleLength < maxLength) {
for (i = articleLength + 1; i <= maxLength; i++) {
$('#list' + i).remove();
$('#article' + i).remove();
}
}
};
var getOnlineFeed = function(url) {
var script = document.createElement('script');
script.setAttribute('src', 'http://ajax.googleapis.com/ajax/services/feed/load?callback=listEntries&hl=ja&output=json-in-script&q='
+ encodeURIComponent(url)
+ '&v=1.0&num=' + maxLength);
script.setAttribute('type', 'text/javascript');
document.documentElement.firstChild.appendChild(script);
};
var getOfflineFeed = function(url) {
var script = document.createElement('script');
script.setAttribute('src', url);
script.setAttribute('type', 'text/javascript');
document.documentElement.firstChild.appendChild(script);
};
Output looks like This:
for(var i=1; i<=maxLength; i++){
document.write(
'<li id="list' + i + '"><img src="#articleImage"/> </li>'
);
I have Played with #articleImage but it doesn't work. I hope someone Outside can help me with this littleBig Problem...
THX
MAsterluke

You should use the url of the thumbnail:
('#articleImage').append('<img src="' + entry.thumbnail.url + '">');

Related

WordPress Theme File Editor will not be modified

I run a store in WordPress.
You are about to add a unique link to the tab on the page.
WordPress can assign a #tag (custom ID) to each tab, but it wants to provide a link that is not this function.
wordpress : "https://www.mypage/#tab-name"
Custom jquery: "myslog://www.mypage/?tab='tab-name filename"
We successfully wrote and applied the code.
The code is functioning normally, and the modified code is not applied.
However, I can't edit it.
When you click File Update, the phrase "File edited successfully." appears.
Why can't I edit it?
functions.php
wp_enqueue_script( "mypage-theme-js", get_stylesheet_directory_uri() . "/js/theme-script.js", array(),'1.2');
js/theme-script.js
jQuery(document).ready(function() {
if (jQuery('.terms-conditions-content').length > 0) {
for (var i = 1; i <= jQuery('.terms-conditions-content .eael-tab-inline-icon li').length; i++) {
var select_val = jQuery('.terms-conditions-content .eael-tab-inline-icon li:nth-child(' + i + ')');
var text = jQuery(select_val).find('.eael-tab-title').text()
var result = text.replace(/\s+/g, '')
select_val.attr('id', result.toLowerCase());
}
var tabVal = '';
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == 'tab') {
var tabVal = sParameterName[1];
}
}
console.log(tabVal);
if(tabVal == 'warranty'){
setTimeout(function() {
jQuery("#warranty").click();
}, 1000);
}
if(tabVal == 'cloud-privacy-policy'){
console.log('Test');
setTimeout(function() {
jQuery("#cloudprivacypolicy").click();
}, 1000);
}
if(tabVal == 'cloud-terms-of-service'){
console.log('Test');
setTimeout(function() {
jQuery("#cloudtermsofservice").click();
}, 1000);
}
if(tabVal == 'terms-of-location-based-service'){
console.log('Test');
setTimeout(function() {
jQuery("#termsoflocation-basedservice").click();
}, 1000);
}
if(tabVal == 'information-we-collect-and-why'){
console.log('hi');
setTimeout(function() {
jQuery("#informationwecollectandwhy").click();
}, 1000);
}
}
enter image description here

Jquery Scroll Loading All The Rows At Once And Should Only Load 5 At A Time

I am using the following script to load more, 5 rows at a time from the database, on scroll. All the rows are loading at once on scroll after the initial loads correctly. In realtime, the first 5 load. Then on scroll the last 14 load at once. Like it rushes to the end instead of incrementally loading 5 at a time. I use the same code for a load more button and it works fine. Same PHP file for both. No issue with that. Can anyone see why all the rows are being loaded on scroll instead of 5 at a time.
<script>
//SET NUMBER OF ROWS TO DISPLAY AT A TIME
rowsPerPage = 5;
$(document).ready(function() {
// GETTING DATA FROM FUNCTION BELOW
getData();
window.onscroll = function() {
if ($(window).scrollTop() >= $('#load-container').offset().top + $('#load-container').outerHeight() - window.innerHeight) {
$('#load-more').html('Loading...');
var rowID = Number($("#row-id").val());
var allCount = Number($("#count").val());
rowID += rowsPerPage;
if (rowID <= allCount) {
$("#row-id").val(rowID);
getData();
} else {
$('#load-more').html('End Of Data');
//$('#load-more').html('');
}
}
}
/* REQUEST DATA */
function getData() {
var rowID = $("#row-id").val();
var allCount = $("#count").val();
$('#load-more').html('Loading...');
$.ajax({
url: 'promotions/newest-load-scroll-data-invalid.php',
type: 'post',
data: {
rowID: rowID,
rowsPerPage: rowsPerPage
},
dataType: 'json',
success: function(response) {
setTimeout(function() {
loadData(response)
}, 1000);
},
});
}
/* LOAD DATA TO PAGE */
function loadData(data) {
var dataCount = data.length;
for (var i = 0; i < dataCount; i++) {
if (i == 0) {
var allCount = data[i]['allcount'];
$("#count").val(allCount);
} else {
var promoID = data[i]['promoid'];
var promoNameNewest = data[i]['promoname'];
var promoNameNewestVideo = data[i]['promoname'];
var promoRefNum = data[i]['promorefnum'];
var promoType = data[i]['promotype'];
var theBanner = data[i]['thebanner'];
var email = data[i]['email'];
var customerType = data[i]['customerType'];
if (email == "") {
if (promoType == "Banner") {
$('#load-container').append('<div class="row-center-center padding-top-5 padding-bottom-2"><div>' + promoNameNewest + '</div></div>');
$('#load-container').append('<div><div class="wrap-content"><img class="mobile-banner-scale" id="visitor-banner-click" src=' + theBanner + '></div></div>');
}
if (promoType == "Video Banner") {
$('#load-container').append('<div class="row-center-center padding-top-5 padding-bottom-2"><div>' + promoNameNewestVideo + '</div></div>');
$('#load-container').append('<div><video class="mobile-video-size" id="visitor-banner-click" src=' + theBanner + ' autoplay muted loop></video></div>');
}
}
if (customerType == "p") {
if (promoType == "Banner") {
$('#load-container').append('<div class="row-center-center padding-top-5 padding-bottom-2"><div>' + promoNameNewest + '</div></div>');
$('#load-container').append('<div><div class="wrap-content"><img class="mobile-banner-scale" id="advertiser-banner-click" src=' + theBanner + '></div></div>');
}
if (promoType == "Video Banner") {
$('#load-container').append('<div class="row-center-center padding-top-5 padding-bottom-2"><div>' + promoNameNewestVideo + '</div></div>');
$('#load-container').append('<div><video class="mobile-video-size" id="advertiser-banner-click" src=' + theBanner + ' autoplay muted loop></video></div>');
}
}
}
$('#load-more').html('Loading...');
}
}
});
</script>
I was able to utilize flags to make it work right with a couple other small changes. Appreciate the input, Taplar.

How to to create as much dynamicEl, as we received from PHP

On main page have Gallery, on click a image need open lightGallery slideshow with images that found on ftp directory, with gallery name that clicked on main page.
PHP for finding images and count it:
<?php
header("Content-Type: application/json");
$dirname = $_POST["galleryName"];
$imgGallery = glob("../gallery/" . $dirname . "/".$dirname."_*.*");
$thumbGallery = glob("../gallery/" . $dirname . "/thumb_*.*");
$countImages = count($imgGallery);
echo json_encode(array("imgNormal" => $imgGallery, "imgThumb" => $thumbGallery, "imgCount" => $countImages));
?>
JS:
$('.info').click(function() {
var galleryName = $(this).closest('.imgGallery').find('img.img-thumbnail').attr('name');
$.ajax({
url: "gallery/imgFinder.php",
dataType: "json",
type: "post",
data: {
galleryName: galleryName
},
success: function(xhr) {
if (xhr.imgCount != 0) {
console.log(xhr.imgNormal);
console.log(xhr.imgThumb);
console.log(xhr.imgCount);
for (var i = 1; i <= xhr.imgCount; i++) {
$(this).lightGallery({
dynamic: true,
dynamicEl: [{ //We need to create as much as we received w "xhr.imgCount"
"src": "/gallery/" + galleryName + "/" + galleryName + "_" + i + ".jpg",
"thumb": "/gallery/" + galleryName + "/" + galleryName + "_" + i + ".jpg"
}]
})
return;
}
} else {
console.log('Gallery \'' + galleryName + '\' has no images');
return;
}
},
error: function(xhr) {
console.error("Some error found");
}
});
});
We need to create as much dynamicEl with image/thumb variables, as we received xhr.imgCount
To get something like this:
dynamicEl: [{
"src": '...',
'thumb': '...'
}, {
'src': '...',
'thumb': '...'
}, {
'src': '...',
'thumb': '...'
}, {
'src': '...',
'thumb': '...'
}]
inside your JS code you needs to be updated something like below:
if (xhr.imgCount != 0) {
console.log(xhr.imgNormal);
console.log(xhr.imgThumb);
console.log(xhr.imgCount);
var dynamicEls = [];
for (var i = 0; i <= xhr.imgCount; i++) {
dynamicEls[i] = {
"src": "/gallery/" + galleryName + "/" + galleryName + "_" + i + ".jpg",
"thumb": "/gallery/" + galleryName + "/" + galleryName + "_" + i + ".jpg"
};
}
dynamicEls.pop(); //For remove unrealized last url/data
$(this).lightGallery({
dynamic: true,
dynamicEl: dynamicEls
});
}
So, I am using and temp variable dynamicEls and after the loop filling it in correct position.

Pass Pagination data to Page

I have a page that I'm trying to get AJAX thumbnail replacement & pagination to work. The page loads the initial thumbs: http://www.partiproductions.com/vault_test/1-a-b.php
But when clicking nav buttons, it should change the thumbnails, but doesn't.
My click function (forward button):
$('#gort').mouseup (function() {
var curpg = parseInt($('.thumbwrap').attr('data-cpg'),10);
console.log('Cur Pg: ' + curpg);
var newpg = curpg + 1;
console.log('New Pg: ' + newpg);
var $totpgs = parseInt($('.thumbwrap').attr('data-tpgs'),10);
console.log('Total Pages: ' + $totpgs);
if (newpg > 1) {$('#goleft').show(200)}
if (newpg == $totpgs) {newpg = $totpgs; $('#gort').hide()} // limit page to total pages
if (newpg < $totpgs) {$('#gort').show(200)}
$('.thumbwrap').attr('data-cpg', newpg);
var $start = (newpg - 1) * 15;
console.log('Start: ' + $start);
// my attempt to pass $start to pagination.php
$.ajax({
url:'pagination.php',
type:'POST',
data:{start:$start},
dataType:'JSON'
success: function(response) {
thumbparse(response);
}
});
});
Currently simple thumbparse function:
function thumbparse(response) {
alert(response);
console.log('Thumbparse output: ' + $navresults);
}
Pagination.php:
<?php
$thumbst = $_POST['start']; // capture input from AJAX
echo "Inside Pagination: $thumbst";
require_once 'meekrodb.2.2.class.php';
require_once 'dconnect.php';
// pull from database using specific page items
$navresults = DB::query("SELECT substr(theme, 1, 1) as Alphabet, theme, developer, thumb, thumb_lg FROM gallery ORDER BY (CASE Alphabet
WHEN '1' THEN 1
WHEN '2' THEN 2
WHEN '3' THEN 3
WHEN 'A' THEN 4
WHEN 'B' THEN 5
ELSE 6
END), theme
LIMIT $thumbst,15");
if(isset($_POST['start']) && !empty($_POST['start'])) {
echo json_encode($navresults);
}
// my attempt to loop through assigned variables that are echoed in main pg
$x = 0;
foreach ($navresults as $row) {
$x++;
if ($x == 1) {
$t1 = $row['theme'];
$d1 = $row['developer'];
$th1 = $row['thumb'];
$thlg1 = $row['thumb_lg'];
}
... other x's
}
I'm not seeing the echoes from pagination.php How do I get the new thumb data ($navresults) passed back to main page and get that data into the DOM? Code please, as I'm just learning - thanks.
Update 1:
function thumbparse(response) {
alert(response);
var obj = JSON.parse(response);
alert(obj.count);
console.log('Thumbparse results: ' + $navresults);
}
Update 2:
function thumbparse(response) {
alert(response);
console.log(response);
var x = 0;
var obj = response;
$.each(obj, function(key, val) {
x++;
var y = x - 1;
$('ul.thumbwrap .thumb:nth-of-type(y) img').attr({
alt: obj.theme,
src: obj.thumb,
'data-retina': obj.thumb_lg
});
$('ul.thumbwrap .thumb:nth-of-type(y) p.hname').text(obj.theme);
$('ul.thumbwrap .thumb:nth-of-type(y) p.hdev').text(obj.developer);
});
}
Update 3:
function thumbparse(response) {
alert(response);
console.log(response);
var x = 0;
var obj = response;
$.each(obj, function(key, val) {
x++;
var y = x - 1;
console.log('Exist. src: ' + $('.thumb').eq(y).find('img').attr('src')); // correct
console.log('New src: ' + obj.thumb); // undefined
$('.thumb').eq(y).find('img').attr({
alt: obj.theme,
src: obj.thumb,
'data-retina': obj.thumb_lg
});
$('.thumb').eq(y).find('p.hname').text(obj.theme);
$('.thumb').eq(y).find('p.hdev').text(obj.developer);
});
}
Update 4:
function thumbparse(response) {
alert(response);
console.log(response);
var x = 0;
var obj = response;
$.each(obj, function(key, val) {
x++;
var y = x - 1;
console.log('Exist. src: ' + $('.thumb').eq(y).find('img').attr('src'));
console.log('New src: ' + obj[key].thumb);
$('.thumb').eq(y).find('img').attr({
alt: obj[key].theme,
src: obj[key].thumb,
'data-retina': obj[key].thumb_lg
});
$('.thumb').eq(y).find('p.hname').text(obj[key].theme);
$('.thumb').eq(y).find('p.hdev').text(obj[key].developer);
if (obj[key].theme == '') {$('.thumb').eq(y).hide()}
});
}
Try this:
function thumbparse(response) {
console.log(response);
var x = 0;
var obj = response;
$.each(obj, function(key, val) {
x++;
var y = x - 1;
console.log('Exist. src: ' + $('.thumb').eq(y).find('img').attr('src'));//Actual src
console.log('New src: ' + obj[key].thumb); //new src from json response
$('.thumb').eq(y).find('img').attr({
alt: obj[key].theme,
src: obj[key].thumb,
'data-retina': obj[key].thumb_lg
});
$('.thumb').eq(y).find('p.hname').text(obj[key].theme);
$('.thumb').eq(y).find('p.hdev').text(obj[key].developer);
if (obj[key].theme == '') {$('.thumb').eq(y).hide()}
});
}

Instagram API: how to make in popular feed see user and likes

I have this code and I want to write before every photo a text and I don't know where to write. By the way, I want to know every photo which is uploaded likes and users.
function loadFeed() {
var param = {access_token:access_token};
cmd(param, onPhotoLoaded);
}
function cmd(param, callback) {
//popular
var cmdURL = 'https://api.instagram.com/v1/media/popular?callback=?';
$.getJSON(cmdURL, param, callback);
}
function onPhotoLoaded(data) {
if(data.meta.code == 200) {
var photos = data.data;
if(photos.length > 0) {
for (var key in photos ){
var photo = photos[key];
$('<div id=p' + photo.id + '></div>').addClass('photoWrapper').appendTo('#panel');
var str = '<img id="' + photo.id + '" src="' + photo.images.standard_resolution.url + '" width="100%">';
$('<div></div>').addClass('photo').html(str).appendTo('#p' + photo.id);
$('#' + photo.id).load(function() {
$('#p' + $(this).attr('id')).fadeTo('slow', 1.0);
});
}
}else{
alert('empty');
}
}else{
alert(data.meta.error_message);
}
}
The data you are looking for is in the photo object.
http://jsfiddle.net/AbU7a/
function loadFeed() {
cmd({access_token:'11007611.f59def8.4f942a67c9174159a1601a037490d3ea'}, onPhotoLoaded);
}
function cmd(param, callback) {
//popular
var cmdURL = 'https://api.instagram.com/v1/media/popular?callback=?';
$.getJSON(cmdURL, param, callback);
}
function onPhotoLoaded(data) {
if(data.meta.code == 200) {
var photos = data.data;
console.log(photos);
if(photos.length > 0) {
for (var key in photos ){
var photo = photos[key];
$('<div id=p' + photo.id + '></div>').addClass('photoWrapper').appendTo('#panel');
var str = '<p>likes: '+ photo.likes.count +'</p><img id="' + photo.id + '" src="' + photo.images.standard_resolution.url + '" width="50">';
$('<div></div>').addClass('photo').html(str).appendTo('#p' + photo.id);
$('#' + photo.id).load(function() {
$('#p' + $(this).attr('id')).fadeTo('slow', 1.0);
});
}
}else{
alert('empty');
}
}else{
alert(data.meta.error_message);
}
}
loadFeed();
View your console (differs depending on your browser) it will show you the data you can get from the photo object.
I started you off by adding the likes count.

Categories