Wiley

Professional WordPress Design and Development Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright 2010 by Wiley Publishing, Inc., Indianapolis, Indiana Published by Wiley Publishing, Inc., Indianapolis, Indiana Manufactured in the United States of America

Dealing With Errors

Any time you are working with queries it's nice to see error messages. By default, if a custom query fails nothing is returned, so it's hard to determine what is wrong with your query. The wpdb class provides functions for displaying MySQL errors to the page. Here's an example of using these functions liveposts wpdb-> get_results( wpdb-> prepare(SELECT ID, post_title FROM wpdb-> posts_FAKE WHERE post_status 'publish') ) The show_errors function must be called directly before you execute a...

How Web Standards Get Your Data Discovered

That is literally what it means. When it was first developed it had the intention of taking content and marking it up in a consistent and meaningful way. Many different HTML tags accomplish this. It was for scientific and academic use and the majority of content fit this nature. Eventually the marketers showed up and got their greasy hands involved. They wanted fancy layouts, graphics, sales pitches, and pretty pink ponies. To accomplish this, designers and developers, both...

Buddy Press

BuddyPress is a set of plugins and themes that add a social networking layer to WordPress MU. All BuddyPress plugins can be themed to match your current web site design. Some of the features available include extended profiles, private messaging, friends, groups, wire and activity streams, status updates, forums, and more Each plugin adds a distinct new social networking feature. All BuddyPress plugins are independent, meaning you can add just the plugins you want and not the entire BuddyPress...

Content Sources

When planning a migration you must decide what data sources you will want to move. Certainly you will want to move the actual content and the related media otherwise this whole exercise is silly. Actual content'' has many different interpretations, however Are you moving posts from an existing blog, documents in a word processing system, static HTML from your current site, or some combination of all of these options We discuss migrating static content briefly in the next section however, most...

Global Variables

A global variable is a variable that has a defined value that can be accessed anywhere within the WordPress execution environment. These variables store all types of information about the Loop content, author, and users, and specific information about the WordPress installation such as how to connect to the MySQL database. Global variables should only be used to retrieve data, meaning you should never write data to these variables directly. Overwriting the global variable values could cause...

Simple Social Networking Badges

There are two different ways to integrate external social networking sites into your own site, and they have very different impacts on your content site. We want you to be able to distinguish between the two, and be able to decide when you may want one over the other. vtl ItHU Uri -liniit1. vd mnlln .irr't Inttjsvrlnp nJIg. J* fj .i 11 FWw-di* HiJttontoiSWr FIGURE 9-1 Sociable social networking button under a WordPress post FIGURE 9-2 Social Media Page sidebar widget FIGURE 9-2 Social Media...

Submitting Plugins and Themes

Submitting plugins to the Plugin Directory is the best way to release a plugin to the public. This also holds true for submitting themes to the Theme Directory. Ultimately you want as much exposure as possible for any theme or plugin that you release. Adding your plugin and theme to the appropriate WordPress.org directory is the best way to accomplish this. Remember that both directories are hooked in the admin side of every current installation of WordPress. This means anyone running WordPress...

M

Johnson, Charles, 327 Joomla project, 6 keywords blacklists, 32 Trac, 353 King, Alex, 237 Kubrik default theme, 184 Miscellaneous SubPanel, 46-47 mobile access, 271-272. See also Android iPhones WPTouch Model-View-Controller design pattern, 6 Most Used categories, 27 Moveable Type, 1 importing from, 40 Mullenweg, Matt, 2 multi-pass Loops, 95 multiple Loops, 81, 94-95 multi-pass, 95 nested, 94-95 MyISAM, 321 MySQL database, 1 cache management, for queries, 284 caching, 321 configuration, 12-16...

Theme Hierarchy And Child Themes

So far in this chapter we have advocated making a local copy of the Sandbox theme, renaming it and making your custom theme in that new directory. This is a good way to get started with theme creation and is how many development teams work today. This method works for us because we know exactly where our template files and CSS files are that need to be edited. The whole theme is self-contained, which minimizes our workflow and deployment efforts and the Sandbox core theme does not update very...

Understanding Taxonomy Relationships

To really understand the relationship between the taxonomy tables it's best to look at a database diagram of the taxonomy table structure, shown in Figure 6-3. As you can see, the three taxonomy tables are joined together by unique IDs. The following is a query to display all posts along with all taxonomy terms assigned to those posts SELECT wt.name, wp.post_title, wp.post_date FROM wp_terms wt INNER JOIN wp_term_taxonomy wtt ON wt.term_id wtt.term_id INNER JOIN wp_term_relationships wtr ON...

Working on the Core

The WordPress software is built by the community, which means anyone can help contribute to the codebase. When we say WordPress is built by the community it doesn't mean anyone can go edit the WordPress source code. To contribute to the WordPress Core you must create a patch file with your changes and submit that file for review. If accepted your changes will be incorporated into the WordPress Core, and will be included in the next version release. Contributing code edits, bug fixes, and...

Using Java Script

One more thing about using JavaScript in your web design you may be tempted at times to base your entire site navigation (or another design element) around a super-cool jQuery plugin. The JavaScript may be a really neat effect, but JavaScript should not be the core of your design. jQuery effects should be the sprinkles you put on top of the frosting on the cake. You need to have a solid foundation so that the site still functions and is aesthetically pleasing, even if the JavaScript sprinkles...

Visual Design Elements

Specifically, are the visual assets of your site helpful or distracting to the user Does the theme reinforce the persona you are portraying with your content or detract from it This is another one of those topics that are open to personal interpretation. Photos and colors have differing subjective responses from different people, but the overall impression of your site should match the general content. For example, a business site should not have a bubble-gum pink theme if it wants to be taken...

Why

Hacking the WordPress Core can make it very difficult to upgrade to the latest version of WordPress. Keeping WordPress current is an important step in overall web site security. If any security vulnerability is discovered a patch is typically released very quickly. If you can't upgrade because you have modified Core files, you are opening up your web site to these security vulnerabilities being exploited and your web site getting hacked. Hacking Core can also lead to an unstable web site...

Migrating Text Documents

We define text documents'' as content primarily associated with a word processor for manipulation, and many text documents will end up as pages in your WordPress site. The content isn't static in the sense that it's fixed, but it's not part of the blog narrative. Brute-force is often the simplest approach here. Copy and paste your text, or export a document as HTML and glue that into a WordPress page. Be warned, however, that most word processing applications insert a huge array of embedded...

Exporting Content

You can export your content from WordPress using the Tools O Export SubPanel. WordPress exports an XML file, referred to as the WordPress eXtended RSS or WXR, that contains all of your posts, pages, comments, custom fields, categories, and tags. This export can also be restricted by author, allowing you to only export posts created by a specific author. Keep in mind that plugins, themes, and settings are not included in the WXR export file. This export is only for your web site's content. The...

Statistics Scalability Security and Spam

> Adding traffic counters to your web site > Caching your content for higher traffic l oads > Keeping your WordPress site healthy and secure > Delegating permissions to your users The past few chapters have covered how to present your fabulous content in effective and beautiful ways, how to increase the likelihood of visitors finding your content, and how to amass all your various content sources into your home web site. What happens when (if ) this all succeeds Well, now you have a...

Feeding Word Press into Facebook

Whereas Twitter is so open and easy to use, on the flip side is Facebook. Also immensely popular, Facebook is the new walled garden of online communities. Various roads exist into Facebook, but very few to get data out. This makes integrating your WordPress site with Facebook somewhat more of a challenge. There are no plugins to take your current Facebook status and post it on WordPress. (Although you can work around this by using Twitter to update both Facebook and your site.) Despite all the...

Plugin Packaging

When developing plugins in WordPress it's best to follow a standard plugin packaging template, that is, certain functional and descriptive components that will exist in all plugins you create for WordPress. This chapter discusses the requirements for a plugin, as well as recommended additions such as software license and internationalization. While the actual code implementation of the plugin is the exciting part of the process, consider the plugin packaging like elementary grammar rules for a...

Web Server Caching and Optimization

Improving WordPress scalability through the web server layer involves PHP execution optimization and web server configuration changes. In both cases, you'll need administrator level access to the web server configuration files. We'll work our way back to the MySQL queries and object caching, but no matter how you end up with a list of pages, WordPress relies on PHP to pull the displayed page together and generate its HTML. PHP is an interpreted language. That means for every execution of the...

Word Press Podcasts

Podcasts are a great way to stay informed on the latest news and information on any topic. Currently, four WordPress-centric podcasts are actively being produced. The WordPress Weekly podcast is a live weekly podcast hosted by Jeff Chandler of WPTavern.com. The show is a roundtable discussion around the top WordPress-related stories of the week. The podcast also features notable members of the WordPress Community for interviews. You can visit the web site at The WordCast Podcast is a weekly...

Plugin Development

> Using WordPress filter and action hooks > How to properly use the Settings API > Create a widget and Dashboard Widget > Data validation and plugin security > Support language translation > Publish a plugin to the official Plugin Directory One of the main reasons WordPress is such a popular software platform is the ease with which it can be extended. Plugins are the primary reason for this and allow almost endless possibilities in extending WordPress. This chapter discusses...

Popular Filter Hooks

More than 1,000 different hooks are available in WordPress, which is a bit overwhelming at first. Luckily, a handful of them are used much more often than the rest. This section explores some of the more commonly used hooks in WordPress. Some of the more common Filter hooks are > the_content Applied to the content of the post or page before displaying. > the_content_rss Applied to the content of post or page for RSS inclusion. > the_title Applied to the post or page title before...

Create a Plugin File

The first step in creating a WordPress plugin is to create a new PHP file for your plugin code. The plugin filename should be descriptive of your plugin so it's easy to identify your plugin in the plugins directory. It should also be unique because all WordPress plugins exist in the same folder. If your plugin filename is too generic you run the risk of another plugin having the same filename, which would be an obvious problem. A plugin can also exist in a folder containing all of the necessary...

Creating the Plugin Header

A requirement for all WordPress plugins is a valid plugin header. The plugin header must be defined at the very top of your main PHP file as a PHP comment. It does not need to exist in every file for your plugin, only the main PHP file. This header tells WordPress that your PHP file is in fact a legitimate WordPress plugin and should be processed as such. Following is an example of a standard plugin header Plugin URI Description This is a brief description of my plugin Version 1.0 Author Brad...

Releasing a New Version

A great feature about WordPress plugins is that you can easily release updates for your plugins in the Plugin Directory. When a new plugin version is released, a notice is displayed on any WordPress site that currently has that plugin uploaded to its server, whether or not it is activated. The user can use the automatic upgrade process to easily upgrade the plugin to the latest version. This is especially important if there are security patches in your plugin to help keep WordPress secure. To...

Statistics Counters

Viewing traffic statistics allows you to see which content on your site is actually bringing visitors in. This shows you what content is working and what is not. In addition, it can show you valuable information about your visitors and their hardware and software setups. Using this information can allow you to tailor your site to accentuate the positive and support your visitors' browsers to create a more pleasant and meaningful experience. Various statistics packages employ a couple of...

Managing Users

You can manage all users across your web site under the Users O Authors & Users SubPanel. Upon accessing this page you are presented with a list of all user accounts in WordPress. Multiple filter types across the top allow you to filter by user roles. You can also search for users using the keyword search box located at the top right. Hovering over any user displays the edit and delete links. You cannot delete the account you are logged in to WordPress with to do that you would need to log...

BbPress

BbPress is an open source forum software package. The goal of bbPress is to be lightweight, powerful, fast, and easy to use. bbPress has many of the features you would expect from message board software, including a simple interface, customizable templates, and spam protection. bbPress can also run plugins to extend its functionality just like WordPress. bbPress was originally offered as a separate installation package, but has since been ported over to a WordPress plugin, and by the time of...

Theme And Presentation

The presentation of your new site represents the next set of decisions for your migration. Is your new site going to look exactly like your old site or are you making a design change at the same time If you are making a design change, you use can an existing theme or build a new theme and not have to dwell on this step too much. Remember to evaluate whether certain content areas need specific, or unique, design considerations. Otherwise, activate your new theme and work out the kinks. However,...

Creating A Plugin Example

Now that you've seen the many different options WordPress provides for use in your plugins, you can put that knowledge to work In this example you will utilize many of the features covered in this chapter. At the end of this section the entire plugin source code will be available. The example plugin you are going to build is called Post Products. The goal of this plugin is to create an easy way to add product data to posts. This plugin will include the following features > settings page using...

Create a Menu and Submenus

WordPress features two different ways to create a custom menu for your plugin. The first thing you'll want to decide is where to locate your options page. The options page link can be located in its own top-level menu (My Plugin Settings), or as a submenu item of an existing menu (Settings O My Plugin Settings). This section explores both methods and how to configure each. The first method you'll explore is creating a new top-level menu. Using a top-level menu is useful if your plugin has...

Setting Up Advertising

Placing advertising on your site is no different than laying out a print page with a mix of editorial and commercial content Decide how many ads you want, where they are going to be placed, and what potential content conflicts you want to avoid. This is as much a design as a technical process, because you have to pay attention to the eventual page presentation and tone of the content when displayed with advertisements. Before running ads on your site, you need to create an account with one of...

BuiltIn Word Press Import Tools

For most WordPress users looking to transport content from one home to another, WordPress offers a variety of built-in import facilities. This section covers the basic conversion process and the use of WordPress eXtended RSS (WXR) files for more flexible or powerful data conversion. WordPress offers basic importers for commonly used blogging platforms. You can find these built-in importers on the Import dashboard in WordPress, and you'll find the corresponding PHP functions implementing them in...

Content Integration Via Feeds

In one situation we've encountered, we managed many sites, normally a subdomain for each department. In this example, each department functions as its own business unit. There are alternatives, but for various reasons each site became a unique WordPress installation. One of the challenges we then face is the duplication of content across multiple sites. Maintaining changes across these separate FIGURE 13-7 OpenID enabled WordPress login page FIGURE 13-7 OpenID enabled WordPress login page sites...

Advanced wpconfig Options

You can set additional advanced options in your wp-config file. These options are not in the wp-config file by default, so you will need to manually add them to the file. To set your WordPress address and blog address, use the following two options define('WP_SITEURL', 'http example.com wordpress') define('WP_HOME', 'http example.com wordpress') The wp_siteurl option allows you to temporarily change the WordPress site URL. This does not alter the database option value for siteurl, but instead...

Integrating Twitter

Even though we just used Twitter as an example of how to integrate any XML feed, let's look at how you could integrate Twitter specifically. Twitter is currently the poster child for open web service APIs. The Twitter API is well documented and easy to use. In addition, it has tons of features. All of this makes integrating your Twitter activities with your WordPress installation a breeze. As such, there are several things you can do with Twitter integration. For example, you can show your...

Create an Options Page

WordPress 2.7 introduced a new Settings API that you will be using for all of the option methods you use in this section. The Settings API is a powerful set of functions to help make saving options in WordPress easy and secure. One of the major benefits of the Settings API is that WordPress handles the security checks, meaning you don't need to include a nonce in your form. The first option page method you'll explore is creating a unique option page for your top-level menu. Remember that when...

Simple Database Queries

When using the wpdb class, you must first define wpdb as a global variable before it will be available for use. To do so just drop this line of code directly preceding any wpdb function call One of the most important functions in the wpdb class is the prepare function. This function is used for escaping variables passed to your SQL queries. This is a critical step in preventing SQL injection attacks on your web site. All queries should be passed through the prepare function before being...

Creating Custom Tables

WordPress contains a variety of tables in which to store your plugin data. However, you might find that your plugin needs a custom table or two to store plugin data. This can be useful for more complex plugins such as an e-commerce plugin which would need to store order history, product and inventory data, and other data that is accessed using database SQL semantics rather than the simple key and value pairing of the options table. The first step in creating a custom database table is to create...

Create a Meta

WordPress features multiple meta boxes on the add new post, page, and link screens. These meta boxes are used for adding additional information to your posts and pages. Meta boxes can be created in a plugin using the add_meta_box function in WordPress. This function accepts six parameters as shown here < php add_meta_box( id, title, callback, page, context, priority ) > Each parameter helps define where and how your meta box is displayed. > id The CSS ID attribute for the meta box >...

Understanding The Loop

Understanding how the Loop functions will help you understand how you can control it. Controlling the Loop to display exactly the content you want will be one of your most used tools in developing WordPress-powered web sites. Because the Loop is at the heart of every WordPress theme, being able to customize the display content opens up the doors to making WordPress look and act however you want. To understand the Loop, it helps to break down the steps WordPress takes to generate a page's...

Showing Only One Category Categoryphp

The category.php template creates a loop of posts from only a specific category. The category template is invoked when a visitor hits a specific URL with the category name in it. This could be something like http example.com category ponies. In the category.php template, WordPress has already determined that your visitor is looking for posts in the particular category requests, so the default loop automatically makes this query for you, no special interaction...

Moving Authors And Users

Most brochureware web sites are author agnostic. That is, you do not really have content attributed to specific site authors, because they are representing a business entity. You can continue with this method, even when using WordPress, which enforces authorship. All you need to do is turn off the author information in your theme. However, if you are moving from a site that has authorship ingrained, or this is something you want to implement on the new site, you will need to set up your authors...

Performance Tuning

Securing and tuning your WordPress installation was covered back in Chapter 11. Be sure to review that content.We're going to touch on more enterprise-specific issues here, with the assumption that in an corporate technology deployment, you'll have access to the web, database, and file servers that comprise the bulk of your WordPress installation. Tuning your theme should be part of any theme development process. That process includes checking the file sizes of all images, making sure the...

Show Your Older Posts by Date Archivephp

Eventually, if you are diligent, your site will have older content. And if you are really industrious you will be able to do those fun one year ago on my site I told you about X'' posts. Eventually you may have copious amounts of content, and so much that it is not feasible or appealing to show it all on the front page. That is, if content is being generated on a regular schedule, there will come a point in time where you will want to refer to something that is clearly not going to be still on...

Word Press News Sites

Many different WordPress-related web sites exist. This section provides a list of the most popular WordPress-focused sites for news and information regarding anything and everything WordPress related. The WordPress Tavern is a web site focused on all things WordPress. This includes BuddyPress, bbPress, WordPress.com, and any project under the Automattic umbrella. The Tavern features a very active message board where members discuss the latest news and developments in the WordPress Community....

Content Identification

All content migration follows a similar pattern Extract bits from the existing repository, automate preparation for the new system as much as possible, and import the content, typically repeating that loop as you find steps that require manual editing or fine-tuning. This section identifies and prepares the content that we want to move to WordPress and walks through the three major approaches to WordPress import functions, starting with the fully manual migration of text documents and then...

Cleaning Up

Even when you are done moving the bulk of the visible content, there is always the final fit and finish work. You have done the heavy lifting and at least have something to look at on the new site. Now you need to go through and review all the content with spot tests and fix any glaring issues and then do some cleaning up and put the final polish on the site. This section also covers some steps of the go live'' process of launching a site. The balance between when you can make these final...

The Loop

> Understanding the flow of the Loop and where it can be used > Learning how the Loop determines what content to display > Customizing the Loop with different granularities of data access > Understanding template tags and how they work > Understanding global variables and their relationship to Loop processing > Working outside of the Loop The Loop refers to how WordPress determines what content (posts and pages) to display on a page you are visiting. The Loop can display a single...

Theme218 Wordpress Shop

Action hooks, 127-132 Active Directory AD , 324-325 AD. See Active Directory additional hardware. See hardware, addition of admin accounts, 289-290 administrators, 34 WordPress role system, 296 advertising, of content, 242-247 monetization, 242-243 pay-per-click model, 243 pay-per-day model, 243 pay-per-view model, 243 setup, 243-247 conflict resolution, 246-247 editorial control, 244 manual placement, 245-246 plugins, 243-244 Akismet, 32-33 automated spam detection, 287 All Things D, 3 Allow...

Using Your Custom Taxonomy

Now that you've created your custom taxonomy you need to know how to use it on your web site. As always, WordPress features some very easy-to-use functions for working with your custom taxonomy. The following shows how you can display a tag cloud showing your custom taxonomy terms lt php wp_tag_cloud array 'taxonomy' gt 'ingredients', 'number' gt 5 gt The wp_tag_cloud function can accept a lot of different arguments, but in this example you're only using two taxonomy and number. First, you set...

Uninstall Your Plugin

A nice feature to include with your plugin is an uninstall feature. WordPress features two ways to register the uninstaller for your plugin the uninstall.php method and the uninstall hook. Both methods are executed when a deactivated plugin is deleted in WordPress. The first method you'll look at is the uninstall.php uninstaller method. This is the preferred method for uninstalling a plugin. The first step to using this method is to create an uninstall.php file. This file must exist in the root...

About The Technical Editor

MIKE LITTLE is the co-founding developer of the WordPress project. He started WordPress in 2003 with Matt Mullenweg now of Automattic Inc. and has been developing with and using it ever since. He now runs zedl. com, his web development and consultancy company, which specializes in WordPress. He recently worked on a number of government WordPress sites, most notably a Law Commission consultation site, and now develops and supports a site for a large Cabinet Office client. He is a published...