WordPress – jQuery

WordPress will load jQuery automatically without you having to add the files yourself. I’ve seen a different methods, some of which do not always work. Here’s the method I use that seems to work reliably.

The following would be added to your functions.php file. If you don’t have a functions.php yet, create one, in your theme folder.

 

<?php 
function theme_init() {
	if (!is_admin()) {
		wp_enqueue_script('jquery');
	}
}
add_action('init', 'theme_init');

 

Note! There can be no characters, this include spaces, or extra lines, in front of the tag. This is good practice. Extra characters outside of the php tag will cause the server to create HTTP header and send it to the browser before WordPress is ready.

If you already have a funtions.php file in your theme, you can add the snippet above, without the <?php.

WordPress loads jQuery in “No Conflict” mode. This means that jQuery will be accessed through the variable jQuery rather than the $. To work with this easily, set up your document ready actions like this:

jQuery(function($){ // Notice the $ here!
	$("#box>div>div").eq(0).siblings().hide();
	$("#box>ul>li.slide-thumb").click(function(event){
		var index = $(this).index();
		$("#box>div>div.slides").fadeOut(400).eq(index).fadeIn(400)
	});
});

Notice here, that jQuery (note the uppercase Q!) replaces the $ outisde the ready function. While inside the function I’ve used the $. This is possible by including the $ as a parameter to the function inside jQuery(function($){}). Placing this variable here allows jQuery to assign itself to this name, so inside of the function you can use that variable in place of jQuery.

WordPress – Custom Menu

Custom menus are a great options for WordPress. A menu is basically a list of links. This list of links can appear anywhere in your theme. You can customize the links that appear in the list via the admin panel.

A theme may contain as many custom menus as you care to add. Each can be customized through the admin panel. Custom menus can appear anywhere in your site you care to place them.

To get started create a function.php file in your theme folder.  Next add a <?php ?> tag to your functions.php file. Your functions.php should contain one <?php ?> tag and all of the custom php code should go between the <?php and ?>.

Now add the code to generate a new custom menu. Add the following inside the <?php and ?>:

// Notify WordPress that you want to run a function when the page initializes
add_action( 'init', 'register_my_menus' );

// Here's the function
function register_my_menus() {
   // Call this function to register a new menu
   // Declare a slug-name and a display name for the new menu
   register_nav_menus(
      array('header-menu' => __( 'Header Menu' ) )
   );
}

The first line tells WordPress to call on the function resgister_my_menus when the page initializes. The register_my_menus function is defined below. This functions calls on register_nav_menus, which is defined by WordPress. This function receives an Array describing the menu to create.The menu gets two names. A slug name which is used in code to refer to the menu. The other is a display name which is used when the name appears in a page.

The __() function used to wrap the display name, as in __(‘Header Menu’) is a special function used translate your page in to other languages. See the codex for more information. This function is not required but is good practice to include.

For more info refer to the codex: http://codex.wordpress.org/Function_Reference/wp_nav_menu

WordPress – functions.php

The functions.php file is a file that can be ioncluded in anything theme you might create for WordPress. This file is used to add unique functions to your WordPress theme. The functions.php file you can add new functionality to your site and modify the regular functions of WordPress. You can also gain access to many features of WordPress that are not available through the admin panel.

To use functions.php just create a plain text file named functions.php and add it to your theme folder. From here you will code that file that adds features to your theme.

Note: Every theme will have it’s own functions.php file and the features added by that file will only be in effect when that theme is active.

Wordrpess as CMS

It seems that WordPress must be one of the most popular CMS tools available at this time. Obviously this has a lot to do with how easy it is to work with. Installation is a snap, they boast a 5 minute install, and I have to say it’s pretty accurate. Though, it might take a few minutes longer if you’re new to the process. That said I’ve never heard anyone claim the “5 minute” install was very inaccurate.

From here you start to wonder what kind of sites can make with WordPress? This question is tainted by the blog label. Since it started as a blog, WordPress.com us a blog hosting site, and it’s primary use is as a blog. Everyone’s first thought is that WordPress is a blog.

Really, WordPress is a Content Management System, or CMS. Originally conceived as a blog, it’s really just a site manager that stores site content as either posts or pages. Posts are elements that are added often, think of these as blog posts. Pages on the other hand represent content that is more or less fixed, think of this as a static web pages.

Working with these two types of elements there is a broad range of web sites that can be created. Not just blogs.

WordPress provides several methods of organizing site content. Categories, which are, well, categories. Categories allow you to sort content into groups that can be searched, filtered and displayed together. Categories also allow you style types of content differently.

Tags are another organizing tool that provide a free form method of, well, tagging content. Think of tags as keywords attached to content to provide a more detailed description. Use tags to build on the broad areas of content created by categories.

WordPress also provides a system of taxonomies. Think of taxonomies as a specialized tagging. Or, categories of tags. The taxonomy system is not activated by default. To use this you’ll need to activate this feature using the functions.php file. See this tutorial here: http://justintadlock.com/archives/2009/05/06/custom-taxonomies-in-wordpress-28

What types of sites can you make with WordPress? It’s hard to say how much you can do with WordPress. If you’re new to WordPress, I would that you probably do a lot more than you think you can. The tool is very flexible. The Admin panel is also incredibly easy to pick. So it’s pretty is to create a site and pass it to a client to manage with minimal instruction.

Here’s an article on sites using WordPress as a CMS: http://www.webhelpermagazine.com/2008/04/wordpress-wow-seven-top-sites-using-wordpress-as-a-cms/

Looks like I’m not the only one that thinks WordPress is a great CMS tool. Looks like Pakt Publishing awarded WordPress first place Overall Best Open Source CMS. WordPress beat Drupal and Joomla. Which are dedicated CMS tools. Here’s a link if you’d like to read more about this: http://www.packtpub.com/award