我一直在使用以下脚本的变体从日历的 XML 提要中提取事件信息并将其显示在 html 页面中:
$(document).ready(function () {
$.ajax({
type: "GET",
url: "../../../evanced/lib/eventsxml.asp?dm=exml&nd=14&fe=1&alltime=1",
dataType: "xml",
success: xmlParserFeatured,
error: function(){alert("We're sorry. Something didn't load correctly.");}
});
});
function xmlParserFeatured(xml) {
$(xml).find("item").each(function () {
var xml_image = $(this).find('imagepath').text();
var xml_imagetext = $(this).find('imagetext').text();
var xml_title = $(this).find('title').text();
var xml_date = $(this).find('date').text();
var xml_time = $(this).find('time').text();
var xml_endtime = $(this).find('endtime').text();
var xml_location = $(this).find('location').text();
var xml_link = $(this).find('link').text();
var xml_description = $(this).find('description').text();
var xml_signup = $(this).find('signup').text();
var xml_eventtype = $(this).find('prieventtype').text();
var hasImage = xml_image != "" && xml_image != "";
var hasDate = xml_date != "";
var noEndTime = xml_time != "" && xml_endtime == "";
var hasEndTime = xml_time != "" && xml_endtime != "";
var hasLink = xml_link != "";
var hasDescription = xml_description != "";
var hasLocation = xml_location != "";
var hasSignUp = xml_signup == "1";
var eventType = xml_eventtype == "Outreach" || xml_eventtype == "Teen" || xml_eventtype == "Youth";
var content = ((eventType) ? "<div class='article " + xml_eventtype + "'>" : "<div class='article Adult'>") +
((hasImage) ? "<img class='article' src='" + xml_image + "' alt='" + xml_imagetext + "' />" : "")
+ "<p class='article_heading'>" + ((hasLink) ? "<a href='" + xml_link + "'>" + xml_title + "</a></p>" : "<p class='article_heading'>" + xml_title + "</p>")
+ "<p class='article_subheading'>" + xml_date + ((hasEndTime) ? " from " + xml_time + " to " + xml_endtime : "") + ((noEndTime) ? " at " + xml_time : "") + ((hasLocation) ? "<br />Location: " + xml_location + "</p>" : "")
+ ((hasDescription) ? "<p>" + xml_description + "</p>" : "")
+ ((hasSignUp) ? "<p><a href='" + xml_link + "'>Register Online</a>.</p>" : "")
+ "<div style='clear: both; height: 1px;'></div></div>";
$(".event_list").append(content);
});}
我们正在将我们的网站迁移到 WordPress,但我无法让它在任何 WP 页面上运行。我的问题是 a.)这是否可以在 WordPress 中工作和 b.)是否有另一种/不同/更好的方法可以在 WordPress 中获得相同的结果?我在网上找到的大部分内容都讨论了将 XML 提要导入为博客文章,这不是我想要的。