Hello,
I've inherited some code at work from a colleague who has left. It's
javascript (see below) that displays the contents of a wordpress events
feed on a plain html page, via the google api.
There's a custom node/field/thing that I had to add to the feed so we can
ouptut the event date rather than the published date -
<eventDate>...</eventDate>.
After extensive googling, I now know pulling in the custom
node/field/whatever-it's-called from the rss requires google to output it
in xml or mixed format. I also know I need to use getElementsByTagName or
getElementsByTagNameNS to target <eventDate>. However the best I can do is
to get it to output "undefined" or "[object NodeList]" as text.
The line I've tried adding is in bold below, just below the commented out
published date lines we are currently using - obviously that's not ideal
for events!
If anyone could explain what I need to do, it would be most appreciated.
I'm really not au fait with this kind of thing coming from a design
background.
function loadEventsFeeds(feedUrl, numEntries) {
var feed = new google.feeds.Feed(feedUrl);
feed.setResultFormat(google.feeds.Feed.MIXED_FORMAT);
feed.setNumEntries(numEntries);
feed.load(function(result) {
if (!result.error) {
var container = document.getElementById("events-feed");
// Handle the featured item
var entry = result.feed.entries[0];
if (entry == null) {container.innerHTML = "<p>There are currently no items
in this category. However we are constantly updating our news and events so
please check back again soon.</p>";}
var newsBlockOuterEl = document.createElement("div");
newsBlockOuterEl.setAttribute("class", "col_title_content float_left");
var newsBlockImgWrapper = document.createElement("div");
newsBlockImgWrapper.setAttribute("class", "span-7 col float_left");
newsBlockOuterEl.appendChild(newsBlockImgWrapper);
var newsBlockTextOuterWrapper = document.createElement("div");
newsBlockTextOuterWrapper.setAttribute("class", "span-7 last col");
//newsBlockTextOuterWrapper.setAttribute("class", "span-14 last col");
var newsBlockTitleWrapper = document.createElement("div");
newsBlockTitleWrapper.setAttribute("class", "theme_colour cufon_me
font_size_18 float_left");
newsBlockTitleWrapper.innerHTML = "<a
href='"+entry.link+"'>"+entry.title+"</a>";
newsBlockTextOuterWrapper.appendChild(newsBlockTitleWrapper);
newsBlockTextOuterWrapper.innerHTML += "<br class='clear' />";
var date = document.createElement("p");
date.setAttribute("class", "small");
//date.innerHTML = "Published on ";
//date.appendChild(document.createTextNode(formatDate(new
Date(entry.publishedDate))));
*date.innerHTML = date.getElementsByTagName("eventDate");*
newsBlockTextOuterWrapper.appendChild(date);
var newsBlockContent = document.createElement("p");
newsBlockContent.setAttribute("class", "noImage");
newsBlockContent.innerHTML += entry.content;
newsBlockTextOuterWrapper.appendChild(newsBlockContent);
// Find and assign image
var imgEls = newsBlockContent.getElementsByTagName("IMG");
if (imgEls.length == 0) {
imgEls[0] = document.createElement("img");
imgEls[0].setAttribute("width", "215");
imgEls[0].setAttribute("height", "150");
imgEls[0].setAttribute("alt", entry.title);
imgEls[0].setAttribute("src",
"http://assets.bournemouth.ac.uk/aqua-retrofit/images/news-default-medium.jpg");
}
imgEls[0].setAttribute("class", "margin_right_10px news_img_large");
newsBlockImgWrapper.appendChild(imgEls[0]);
newsBlockOuterEl.appendChild(newsBlockTextOuterWrapper);
container.appendChild(newsBlockOuterEl);
// End handle featured item
// Handle the other items
for (var i = 1; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
var newsBlockOuterEl = document.createElement("div");
var newsBlockOuterClass = "span-7 col";
if (!(i % 2)) newsBlockOuterClass += " last";
newsBlockOuterEl.setAttribute("class", newsBlockOuterClass);
var newsBlockContent = document.createElement("p");
newsBlockContent.setAttribute("class", "noImage");
newsBlockContent.innerHTML += entry.content;
// Find and assign image
//var imgEls = newsBlockContent.getElementsByTagName("IMG");
//if (imgEls.length == 0) {
//imgEls[0] = document.createElement("img");
//imgEls[0].setAttribute("width", "77");
//imgEls[0].setAttribute("height", "55");
//imgEls[0].setAttribute("alt", entry.title);
//imgEls[0].setAttribute("src",
"http://assets.bournemouth.ac.uk/aqua-retrofit/images/news-default-small.jpg");
//}
//imgEls[0].setAttribute("class", "margin_right_10px news_img_small");
var newsBlockTitleWrapper = document.createElement("div");
newsBlockTitleWrapper.setAttribute("class", "theme_colour cufon_me
font_size_18 float_left");
//newsBlockTitleWrapper.appendChild(imgEls[0]);
newsBlockTitleWrapper.innerHTML += "<a
href='"+entry.link+"'>"+entry.title+"</a>";
newsBlockOuterEl.appendChild(newsBlockTitleWrapper);
newsBlockOuterEl.innerHTML += "<br class='clear' />";
var date = document.createElement("p");
date.setAttribute("class", "small");
date.innerHTML = "Published on ";
date.appendChild(document.createTextNode(formatDate(new
Date(entry.publishedDate))));
newsBlockOuterEl.appendChild(date);
newsBlockOuterEl.appendChild(newsBlockContent);
container.appendChild(newsBlockOuterEl);
}
}
});
}
Thanks
--
--
You received this message because you are subscribed to the Google
Groups "Google AJAX APIs" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
To view this message on the web, visit
https://groups.google.com/d/msgid/google-ajax-search-api/3be4d727-0832-4fe2-b434-ba70dda93844%40googlegroups.com
For more options, visit this group at
http://groups.google.com/group/google-ajax-search-api?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"Google AJAX APIs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.