Use the Vertical Scroll plugin with a shortcode

This post comes again from a client request. They were using the Vertical Scroll plugin for WordPress. However, they needed this scrolling box to work on their multilingual site (Chinese & English). But with this plugin, there’s no shortcode, or way to include it in a translatable page. So, I wrote a really quick plugin enhancement. Check it out, hope you find it useful:

GetListItems not showing all columns in SharePoint

I struggled with this for a while today. I was using SPServices’ GetListItems to pull data from SharePoint. I was using an external content type, and for the life of me could not figure out why the query was only pulling in some of my columns. The others just weren’t there. So I searched the web for a while, coming up with nothing that seemed to pertain to me. So I decided to look at my data. Turns out those columns didn’t have any data! So, in short, look at your data! I was using SPXmlToJson, as well as just the standard $.each() function to try to pull those columns; but with no data, nothing was coming back.

Bottom line: look at your data first!

Embed Tudou and Youku videos in WordPress

The challenge this morning was to create a way for a client to embed Tudou videos (Chinese equivalent of Youtube) on their WordPress site in a really easy way. There’s nothing really out there for this, so I decided to take 30 minutes and just write my own plugin. It’s really basic, but it does the job. While I was writing it, I figured I’d also include the ability to embed Youku videos as well. It uses iframes, but could easily be modified to use the embed code or whatever. So, download and enjoy! Or just copy the script here and put in your plugins folder!

Usage:

Find the ID of the video by looking in the URL of your video on Tudou or Youku. Then use that ID in the following shortcode on any post or page:

Tudou videos: [vid site="tudou" id="xxxxxx"]

Youku videos: [vid site="youku" id="xxxxxx"]

Download

Download the plugin here: youku-tudou-embed.zip

Source Code

Here’s the source code. Note: this is based on a tutorial on tutsplus.

Part 2: Sort a javascript array of dates from SharePoint

This is more of a follow-up to my post yesterday on how to convert dates from SharePoint to javascript. Today I’ll show you how to pull a list of dates from SharePoint (as well as other fields), push them into an array, and then sort that array by date.

Problem: Pull a list of reservations from a SharePoint and order them chronologically. There are three fields, firstName, lastName, and startTime. We want to pull all three fields, and then output those fields into an unordered list. As an added trick, we have several reservation lists we need to pull from (Elementary School, Middle School, and High School). So all reservations need to be pulled, and then sorted chronologically.

Solution 1: Just modify your CAML query to OrderBy the startTime field. Well, this works fine. But when pulling from multiple lists (using SPServices), the results will essentially be “grouped” by list.

Solution 2: Push all results to a javascript array, then sort the array. The problem here is that SharePoint’s date/time field isn’t very javascript-y. So sorting won’t work.

Solution 3: Use the convertSPDate() function mentioned in yesterday’s post on converting dates from SharePoint to javascript, then follow solution 2!

Here’s the code (commented with explanations):

Convert a SharePoint date/time field to a javascript Date() object

In a recent project I was looking for a way to sort an array of dates brought back from SharePoint. This worked fine in Chrome, but then I realized it didn’t work in any other browsers! So, by writing a few console.log() lines to test with Safari & FireFox, I discovered that the date that SharePoint passes is seen to javascript as an “invalid date” to almost all browsers. So, here’s a small helper function that just converts what you get from SharePoint into a true javascript Date() object. Hope you find it helpful! I’ve also included it in my code section as a Gist, so grab just the function there if you’d like.


function convertSPDate(d) {
/*
*	A function to convert a standard SharePoint
*	date/time field (YYYY-MM-DD HH:MM:SS) to a
*	javascript Date() object
*
*	Author: Ben Tedder (www.bentedder.com)
*/
    // split apart the date and time
	var xDate = d.split(" ")[0];
	var xTime = d.split(" ")[1];

    // split apart the hour, minute, & second
	var xTimeParts = xTime.split(":");
	var xHour = xTimeParts[0];
	var xMin = xTimeParts[1];
	var xSec = xTimeParts[2];

    // split apart the year, month, & day
	var xDateParts = xDate.split("-");
	var xYear = xDateParts[0];
	var xMonth = xDateParts[1];
	var xDay = xDateParts[2];

	var dDate = new Date(xYear, xMonth, xDay, xHour, xMin, xSec);
	return dDate;
}

	// create a couple of variables
	var startTime;
	var convertedStartTime;

	// a standard SPServices call
	$().SPServices({
		operation: "GetListItems",
		webURL: myListURL,
		async:false,
		listName: myListName,
		CAMLRowLimit: 1,
		completefunc: function (xData, Status) {
			$(xData.responseXML).SPFilterNode("z:row").each(function(i){
				// set the value of startTime to standard SP date/time field
				startTime = $(this).attr("ows_startTime");
			})
		}
	});

	// set the convertedStartTime to a true javascript date
	convertedStartTime = convertSPDate(startTime);

Quick Fix: Set password for phpMyAdmin on WAMP

When you install WAMP for the first time, phpMyAdmin’s ‘root’ account does not have a password. So, when you’re trying to install WordPress it will give you an error saying it can’t make a database connection. In order to fix this (I’m in phpMyAdmin version 3.5.1), go to the “Users” section and click “Edit Privileges” next to the root user. Then scroll down and add a password.

Finally, stop WAMP services and go to C:\wamp\apps\phpmyadmin3.5.1. Edit the config.inc.php file and add a password (for me it’s on line 16):

$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'root';

Restart WAMP services and you should be ready to go!

WP-Cycle with Previous and Next navigation buttons

So I’m not entirely sure the correct method of doing this, so Nathan Rice, if you’re out there, let me know if you want to take this for your own!

WP-Cycle is a great plugin that just simply lets you upload images into a jQuery-based image slider for use in a WordPress page, theme, whatever. What I’ve done is added some functionality to the plugin that adds left/right arrows, as well as adding support for the scrollHorz, which is one of the default options from the original jQuery Cycle plugin. It’s nothing huge, but check out the code below, and if you like it, replace the wp-cycle.php file in the WP-Cycle plugin folder.

And Nathan, thanks for the great code, hope this helps! I’ve added some CSS below line 481, as well as some HTML markup between lines 415 and 432.