jQuery 1.3 With PHP by Kae Verans Book Review

jQuery-1.3-with-PHP-bookI have read through the newest jQuery book out there: jQuery 1.3 With PHP from Packt Publishing by Kae Verans. It’s targeted at experienced PHP developers who want to enhance their applications on the front end with JavaScript and Ajax functionality and uses the jQuery library to do so. You do not necessarily need JavaScript or jQuery experience to follow along, although it helps. If you are a front end developer who already knows jQuery inside and out and are looking to learn more about PHP, this book is not really geared for you.

But If you’re like me, you are not brand new to jQuery and it’s powerful features and ease of use. You probably have already used it in some of your projects and have used the excellent documentation found on their site. As good as the official docs are, there is always room for improvement by using more robust and clearer examples. That’s exactly what you get with “jQuery 1.3 with PHP“.

The examples you can look forward to building include tabs, accordions, form validation, file management, calendars, image manipulation, drag and drop, and data tables. Your PHP skills, along with the excellent and well explained jQuery code found throughout the book for each example, will allow you to add modern and responsive elements very easily and quickly.

If you are a veteran PHP developer and are looking to get started in the front end UI of your applications and web sites, this is the right book with the right angle for you. If you are a MVC framework guy like I am, the server-side PHP code provided is easily adapted to put into your controllers and views.

Disclosure: I was given a copy of the book to review by Packt Publishing. If you want to purchase the book and use a link from my site, I receive a commission.

Set Up a Local PHP Web Development Environment

I came to the realization that it would probably be best to do all of my heavy testing and development on a Ubuntu server locally. I use VirtualBox with Mac OS X as my host and installed Ubuntu 9.10 as a guest. This allows me to use Synaptic Package Manger to install Zend Server which has everything I need to start testing. This is by far the easiest way I have used to set up a local server. Having done that on Windows and Mac, I love the way Synaptic Package Manager handles everything. My only problem came when I needed to have multiple projects going on and wanted a nice way to access them on localhost without using subdirectories.

After a bit of searching, I found this thread and it helped me set up a nice little dev environment. For PHP programmers who are using subdirectories (like I used to), I would recommend using this approach on Ubuntu, because it’s just so easy and very clean. It uses Apache VirtualHosts to access your projects like http://myproject.dev instead of having it in a subdirectory like http://localhost/myproject. This post will also serve as my reference guide for when I need to set up more projects.

This is specifically for setting up a new Zend Framework project on Ubuntu running the Zend Server stack (Apache, MySQL, PHP 5.3, etc.), but could be used for any PHP application or script. One thing to note is that I place all my projects in /home/ryan/web/php. If you have a different place, be sure to change the path where needed.

1. Create an empty file named “projectname” in /home/yourusername/web/sites-enabled and add:

<VirtualHost *:80>
ServerName projectname.dev
DocumentRoot /home/yourusername/web/php/projectname/public
</VirtualHost>

2. Create a symlink to sites-enabled (this step only needs to be done one time, once this directory symlink is established, it will always work):

sudo ln -s /home/yourusername/web/sites-enabled /etc/apache2/sites-enabled

3. Edit your hosts file, sudo gedit /etc/hosts, and add another host to the end:

127.0.0.1 projectname.dev

4. Restart apache: sudo /etc/init.d/apache2 restart

5. Test: http://projectname.dev

So there you have it. While it does take a little longer to set up than a regular subdirectory, (I just tested this out, and took literally 1 minute), it’s definitely worth the extra effort.

Moving On

My last day at the Texas Tech Office of Communications & Marketing was Friday, July 17th. That was my first job coming out of college and I received a lot of great experience and support while working there. I learned a lot more about PHP and using CodeIgniter to develop web applications as well as customizing WordPress as a CMS. These are excellent skills to have, and I don’t know if I would have gotten them at the level that I have now if not for this job.

The people are great and it was a pleasure to work there, but I felt like it was time to move on and see what else was out there. I’m moving back to the Dallas area to be closer to my family and will see what opportunities I can find over there.

It does feel great though to not have to go to bed at a certain time in order to wake up at a certain time. I love the freedom I have now.

If anyone is moving to Lubbock looking for a job and knows PHP and WordPress really well, let me know and I’ll forward on your info. Texas Tech is a great place to work.

Also, if you have any WordPress projects or web applications you need done, contact me.

Now comes the FUN part.. PACKING!

Texas Tech Today got Showcased

This is really cool! Our WordPress site for Texas Tech daily news, Texas Tech Today, was featured in the WordPress.org Showcase. Go check it out :)

It was even covered in part of a presentation which was mentioned over at WPCandy.

I am thrilled at the attention this has been getting. It Just shows that WordPress has the ability to be a full-fledged CMS if you know what to do (programming plugins to fit your needs and making custom templates) and have a vision for your site. See, it was fairly easy for me to come up with a solution for our office. I knew we needed a much better way of publishing stories, feature stories, news releases, clips, and videos. So I set out to design a theme that would display all of these elegantly and provided all the social media and user tools on each individual page.

Once I had a clear vision (in a Photoshop mockup), I started making my plugins and template/css to do what I already had in my head.  I hadn’t been exposed to WordPress programming very much at all prior to this project, but the codex helped tremendously and any answer I was looking for was easy to find.

If anyone has any questions, leave a comment or contact me.

Ajax for WordPress Plugins Using jQuery Tutorial

I recently had the need to perform some ajax functions on the backend of Texas Tech Today and wasn’t sure exactly how to go about it. So after a search, I found this great explanation: Simplified AJAX For WordPress Plugin Developers using Jquery. But it stops short of explaining how to receive some data from a POST, give it to PHP to do something with, and then return a result back to the form.

So, I thought I would detail how to do that in WordPress in a plugin.

The plugin just has a basic options page (Settings -> Ajax4WP) and lets you save an option to the database via ajax. Go ahead and download and install it; you’ll see how simple it is.

1. Create a php file that will have our javascript code, and save it into your plugins folder.

The reason we need our javascript code to be in a PHP file is to get the “get_option(’siteurl’)” value dynamically, since we’ll need that to reference our PHP file with the ajax function.

js-Ajax4WP.php (download the plugin files)

<?php
include('../../../wp-config.php');
$site_url = get_option('siteurl');
?>
jQuery(document).ready(function() {

   //when the link with the id of save_settings is clicked, get the value of the text field and start doing the ajax stuff
   jQuery('#save_settings').click(function() {

      var Ajax4WP_test_setting = jQuery("#Ajax4WP_test_setting").val();

      //action is the name of the php function in your main plugin file
      jQuery.post("<?php echo $site_url; ?>/wp-admin/admin-ajax.php", {action:"Ajax4WP_save_settings", 'cookie': encodeURIComponent(document.cookie), Ajax4WP_test_setting:Ajax4WP_test_setting},
      function(res)
      {
         var message_result = eval('(' + res + ')');
         if (!message_result.success) {
            jQuery("#Ajax4WP_test_setting").css("border","2px solid #cc0000");
         }
         alert(message_result.message + ' ' + message_result.setting);
      });

      return false;
   });

});

This is jQuery ajax code that takes the value of a text field and passes it to Ajax4WP_save_settings() in our plugin file. We use jQuery.post to define a post variable (Ajax4WP_test_setting) that PHP can use.

Once the plugin code does its thing on the server (step 2 below), it returns the result back to this function at “function(res)”. Then we eval the json result and use an alert to display a message.

2. Create your standard plugin file and put in the Ajax4WP_save_settings function.

Ajax4WP.php (download the plugin files)

...

// our ajax action:
add_action('wp_ajax_Ajax4WP_save_settings', array(&$this, 'Ajax4WP_save_settings'), 10);

function Ajax4WP_save_settings()
		{
		   $name = 'Ajax4WP_test_setting';
			$value = $_POST['Ajax4WP_test_setting'];

			if ($value == "") {
				$message_result = array(
					'setting' => "",
					'message' => 'Please enter a Setting Value!',
					'success' => FALSE
	         );
			}
			else {
			   update_option($name, $value);
				$message_result = array(
					'setting' => $value,
					'message' => 'Saved! You entered:',
				   'success' => TRUE
	         );
			}
			echo json_encode($message_result);
			exit;
		}
...

This is standard PHP to process a POST request. When we’re through, we echo the json_encode() result. NOTE: json_encode is a PHP >= 5.2 only function, so be sure you are up to date on your PHP install.

3. Make a php file that will contain basic html and will get included on our settings page

Ajax4WP-settings.php (download the plugin files)

<div id="Ajax4WP Settings" class="inside" style="margin-left: 29px; width: 200px;">

   <h3>Ajax4WP Settings</h3>

   <div id="loading_message"></div>

   <p>
   <label for="Ajax4WP_test_setting">Setting Value:</label>
   <br />
   <input type="text" id="Ajax4WP_test_setting" name="Ajax4WP_test_setting" value="<?php if (isset($this->Ajax4WP_test_setting)) { echo $this->Ajax4WP_test_setting; } ?>" size="20" />
   </p>

   <p><a href="#" id="save_settings" class="button button-highlighted">Save Settings</a></p>

</div>

This is just a “stub” and gets included in our plugin. That way we don’t have a lot of html code mucking up the main plugin file. You can see what’s going on better in the source code when you download the files.

I hope that helps you out if you are wondering how to use jQuery and ajax in your WordPress plugins. Please leave a comment if you have any questions. Thanks!

I Got Mentioned in the LAJ

I was mentioned in a Lubbock-Avalanche Journal article about the PassOrCatch2008.com site :)

“Lisa DuBois-Low and Ryan Pharis from Tech’s communications and marketing department designed and built the site.”

Don Williams wrote the story about how it’s been getting some great recognition around the country. I was watching the Tech vs. K State game on Saturday and the announcers were talking about how it was a neat idea and a good campaign that our athletic department put together. Plus it’s gotten a lot of buzz on the blogs and message boards which is nice to see. Most comments are positive, but you’ll always have the negative posters who like to hate on Tech.

So that was really cool to see, and kinda made my day.

You can read the full article: Tech site gets national attention.

On another note, the LAJ’s RedRaiders.com site is built on WordPress. I think it’s another great example of what wp can do and it’s versatility. Very nice job to whoever implemented that. I’m impressed.

New Project: PassOrCatch2008.com – Crabtree and Harrell

We just launched my favorite project I’ve worked on so far, for obvious reasons for any of you that know me :)

This new site is http://www.passorcatch2008.com and it’s a showcase for two of Texas Tech’s top players: quarterback Graham Harrell and wide receiver Michael Crabtree. If we can keep winning and finish off a great season, both have a shot at the Heisman at the end of the year.

The site features a great design developed by our athletics department. They also shot some fun videos and gave us some nice photos to put up in the gallery.

My job was to take the design and mock it up in photoshop. I then did the html and css conversion. I also added the photo gallery using the jQuery-lightbox plugin.

I received the videos in .avi format so I converted them to .flv format and used the JW FLV Player to play them in flash.

The excellent content work and design was done by our web writer, Lisa Low.

It was a fun site and I’m very happy with the way it turned out. I hope Texas Tech fans everywhere enjoy it and spread the word.

GO TECH!

Post from Word 2007

I’ve never posted from outside of wordpress before. I’m testing out the “Blog Post” feature of Word 2007.

I’m interested to see if it adds clean html markup to the post. When you copy and paste from word to wordpress’ editor, it brings in extraneous mso code.

Edit:

What a cool feature of Word and WordPress! That’s very nice to know. I’ll have to check out Windows Live Writer now.

Texas Tech Today Featured on WeLoveWP and eduStyle

The fine folks at We Love WP and eduStyle have put Texas Tech Today in their galleries here and here.

We Love Wp focuses on displaying standout sites/designs that use the WordPress platform as their cms. The sites featured here give you a great indication of the power and flexibility that you get free with wp.

eduStyle showcases university-based web designs. They have quite a nice community of campus web masters and designers over there.

I’ve always wanted something I’ve designed to be in showcases like these. It’s really cool to have that happen.

I submitted it to some other CSS galleries, so we’ll see how that goes too.

Texas Tech Today 2.0 is LIVE!

Texas Tech Today Screenshot

Whew! A few hard months of planning and preparation have come to a culmination with the launch of the new Texas Tech Today. TTT is our news and information site that holds all of our news releases, clips, stories, and videos. It all runs on WordPress with the help of some custom plugins and templates. This isn’t a typical blog site, and the extendability of WordPress allowed me to do some really cool things and use it as a CMS that will fit our needs very well. This is a credit to the developers of wp, and the fact that they have made it such a nice platform to work with.

This new version will make the posting of stories faster and more efficient. That way, our content developers can focus on producing more and more quality content that our audience will find valuable and want to share.

The old way of posting stories to our site was through dreamweaver and was completely file based, with no help from a cms of any sort. This worked ok for a while, but we realized there had to be a better way to manage our content. Since our stories are somewhat “templatable”, meaning they can have a standard sidebar and other options, I set out to find a way to make it dead easy to post a story without using dreamweaver. Enter wordpress and the ability to code plugins that do pretty much whatever you can think of, and we were set.

We used to have our stories and videos on one server and clips and news releases on another. The news releases and clips were pushed out with a custom mini-cms I built in CodeIgniter. The new way allows us to have everything in one place and the built-in rss feeds for every category make it easy to send out our feeds for each type of post.

Moving to WordPress will hopefully get us a little better search engine placement and maybe some chatter in the blogosphere. Wp-stats is amazing, but we’ve also got google analytics running so we can have a comprehensive view of our visitors and their interests in our content to serve them better.

My hope is that this can be a showcase of the power that wordpress has and that we can lead the way for other universities to use this wonderful software.