Loading...
April 15, 2013#

WordPress Class

Hey BDW @ Night folks – it looks like CU has canceled classes for the evening – so let’s do the same.

We can talk next week and figure out if we want to re-schedule, do something via skype or google hangouts or extend the class a week.

Let me know if you have any questions.
See ya next week
Hank

April 1, 2013#

Custom WordPress Post Types

You are gonna want to grab this plugin Easy Content Types
Here’s a nice zip file of it. easy-content-types

Chicken Meta

<?php $meta_values = get_post_meta($post->ID); ?>
 
<ul>
<li><strong>Temperament:</strong> <?php echo $meta_values['ecpt_temperament'][0]; ?></li>
<li><strong>Egg Yield:</strong> <?php echo $meta_values['ecpt_typicaleggyield'][0]; ?></li>
<li><strong>Additional Notes:</strong> <?php echo $meta_values['ecpt_additionalnotes'][0]; ?></li>
</ul>

Single Chickens

<?php get_header(); ?>
test
<!-- Row for main content area -->
	<div class="small-12 large-8 columns" role="main">
 
	<?php /* Start loop */ ?>
	<?php while (have_posts()) : the_post(); ?>
		<article <?php post_class() ?> id="post-<?php the_ID(); ?>">
			<header>
				<h1 class="entry-title"><?php the_title(); ?></h1>
				<?php reverie_entry_meta(); ?>
			</header>
			<div class="entry-content">
				<?php the_content(); ?>
			</div>
			<footer>
				<?php wp_link_pages(array('before' => '<nav id="page-nav"><p>' . __('Pages:', 'reverie'), 'after' => '</p></nav>' )); ?>
				<p><?php the_tags(); ?></p>
			</footer>
			<?php comments_template(); ?>
		</article>
	<?php endwhile; // End the loop ?>
 
	</div>
	<?php get_sidebar(); ?>
 
<?php get_footer(); ?>

What the hell is a custom post type anyway?

A Custom Type is a Post Type you define. http://codex.wordpress.org/Post_Types#Custom_Types. Custom Post Types became part of the core in WordPress 3.0.

Potential Custom Post Types

  • Real estate listings.
  • Event calendar (I know a lot of folks are interested in this).
  • Movie Database
  • Book Database
  • A forum without a lot of integration problems.
  • A ticket system like the WordPress Trac.
  • Design gallery/showcase.
  • Teams

Adding a custom type to WordPress is done via the register_post_type function. This function allows you to define the post type and how it operates within WordPress.

Here’s a basic example of adding a custom post type:

1
2
3
4
5
6
7
8
9
10
11
12
13
add_action( 'init', 'create_post_type' );
function create_post_type() {
	register_post_type( 'acme_product',
		array(
			'labels' =&gt; array(
				'name' =&gt; __( 'Products' ),
				'singular_name' =&gt; __( 'Product' )
			),
		'public' =&gt; true,
		'has_archive' =&gt; true,
		)
	);
}

Labels

The above example uses 2 labels – but many more are available.

  • name: The plural form of the name of your post type.
  • singular_name: The singular form of the name of your post type.
  • add_new: The menu item for adding a new post.
  • add_new_item: The header shown when creating a new post.
  • edit: The menu item for editing posts.
  • edit_item: The header shown when editing a post.
  • new_item: Shown in the favorites menu in the admin header.
  • view: Used as text in a link to view the post.
  • view_item: Shown alongside the permalink on the edit post screen.
  • search_items: Button text for the search box on the edit posts screen.
  • not_found: Text to display when no posts are found through search in the admin.
  • not_found_in_trash: Text to display when no posts are in the trash.
  • parent: Used as a label for a parent post on the edit posts screen. Only useful for hierarchical post types.

with full arguments it’d look like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
'labels' =&gt; array(
	'name' =&gt; __( 'Super Dupers' ),
	'singular_name' =&gt; __( 'Super Duper' ),
	'add_new' =&gt; __( 'Add New' ),
	'add_new_item' =&gt; __( 'Add New Super Duper' ),
	'edit' =&gt; __( 'Edit' ),
	'edit_item' =&gt; __( 'Edit Super Duper' ),
	'new_item' =&gt; __( 'New Super Duper' ),
	'view' =&gt; __( 'View Super Duper' ),
	'view_item' =&gt; __( 'View Super Duper' ),
	'search_items' =&gt; __( 'Search Super Dupers' ),
	'not_found' =&gt; __( 'No super dupers found' ),
	'not_found_in_trash' =&gt; __( 'No super dupers found in Trash' ),
	'parent' =&gt; __( 'Parent Super Duper' ),
),

The public argument
catchall argument for several other arguments and defaults to false. Depending on whether it’s set to true or false, it’ll automatically decide what other arguments should be unless they’re specifically defined. If you’re looking for finer control over the public arguments, there are three specific arguments you may set:

  • show_ui: Whether to show the administration screens.
  • publicly_queryable: Whether queries for this post type can be performed from the front end.
  • exclude_from_search: Whether the posts should appear in search results.
1
2
3
4
'public' =&gt; true,
'show_ui' =&gt; true,
'publicly_queryable' =&gt; true,
'exclude_from_search' =&gt; false,

Menu Position
By default, a new post type is added after the Comments menu item in the admin. But, you have to ability to move it to a position more suitable for you. Default WordPress menu items are set apart by integrals of 5. For example, using 20 will add your menu item after Pages.

1
'menu_position' =&gt; 20,

Menu Icon
New post types will default to the Posts menu icon, but if you want to mix it up a bit or give your post type some separation from other elements, you can define a custom icon. You only have to input a a custom URL to an image file.

1
'menu_icon' =&gt; get_stylesheet_directory_uri() . '/images/super-duper.png',

Hierarchical
The hierarchical argument allows you to choose whether you want your post type to be hierarchical. It defaults to false. If you set it to true, your posts will behave like pages in WordPress.

1
'hierarchical' =&gt; true,

Query Var
The query_var argument allows you to control the query variable used to get posts of this type. For example, you could use it with the query_posts() function or WP_Query class. This will default to the name of your taxonomy.

1
'query_var' =&gt; true,

Supports
The supports argument allows you to define what meta boxes and other fields will appear on the screen when editing or creating a new post. This defaults to title and editor. There are several available options:

  • title: Text input field to create a post title.
  • editor: Content input box for writing.
  • comments: Ability to turn comments on/off.
  • trackbacks: Ability to turn trackbacks and pingbacks on/off.
  • revisions: Allows revisions to be made of your post.
  • author: Displays a select box for changing the post author.
  • excerpt: A textarea for writing a custom excerpt.
  • thumbnail: The thumbnail (featured image in 3.0) uploading box.
  • custom-fields: Custom fields input area.
  • page-attributes: The attributes box shown for pages. This is important for hierarchical post types, so you can select the parent post.
1
'supports' =&gt; array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail' ),

Rewrite
The rewrite argument allows you to define the permalink structure

  • slug: The slug you’d like to prefix your posts with.
  • with_front: Whether your post type should use the front base from your permalink settings (for example, if you prefixed your structure with /blog or /archives).
1
'rewrite' =&gt; array( 'slug' =&gt; 'cool', 'with_front' =&gt; false ),

Taxonomies
If you have some preexisting taxonomies (or want to create some) you can allow posts of this type to also use those taxonomies. You just have to set an array of taxonomy names that you’d like for it to use.

1
'taxonomies' =&gt; array( 'post_tag', 'category '),

Can Export
You can use the can_export argument to decide whether posts of your post type can be exportable via the WordPress export tool.

1
'can_export' =&gt; true,

Custom Taxonomies

This is a great post – so we’re just gonna use it.
http://wp.smashingmagazine.com/2012/01/04/create-custom-taxonomies-wordpress/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function player_taxonomy() {
	$labels = array(
	    'name' =&gt; _x( 'Team', 'taxonomy general name' ),
	    'singular_name' =&gt; _x( 'Team', 'taxonomy singular name' ),
	    'search_items' =&gt;  __( 'Search Teams' ),
	    'all_items' =&gt; __( 'All Teams' ),
	    'parent_item' =&gt; __( 'Parent Team' ),
	    'parent_item_colon' =&gt; __( 'Parent Team:' ),
	    'edit_item' =&gt; __( 'Edit Team' ), 
	    'update_item' =&gt; __( 'Update Team' ),
	    'add_new_item' =&gt; __( 'Add New Team' ),
	    'new_item_name' =&gt; __( 'New Team Name' ),
	    'menu_name' =&gt; __( 'Team' ),
	); 
 
   register_taxonomy(
	    'leagues',
	    'players',
	    array(
	        'hierarchical' =&gt; true,
	        'labels' =&gt; $labels,
	        'query_var' =&gt; true,
	        'rewrite' =&gt; array('slug' =&gt; 'leagues')
	    )
	);
}
add_action( 'init', 'player_taxonomy' );
 
add_action( 'init', 'players' );
function players() {
	register_post_type( 'players', array(
		'labels' =&gt; array(
			'name' =&gt; __( 'Players' ),
			'singular_name' =&gt; __( 'Player' ),
			'add_new' =&gt; __( 'Add New' ),
			'add_new_item' =&gt; __( 'Add New Player' ),
			'edit' =&gt; __( 'Edit' ),
			'edit_item' =&gt; __( 'Edit Player' ),
			'new_item' =&gt; __( 'New Player' ),
			'view' =&gt; __( 'View Players' ),
			'view_item' =&gt; __( 'View Player' ),
			'search_items' =&gt; __( 'Search Players' ),
			'not_found' =&gt; __( 'No Players found' ),
			'not_found_in_trash' =&gt; __( 'No Players found in Trash' ),
			'parent' =&gt; __( 'Players' ),
		),
		'public' =&gt; true,
		'show_ui' =&gt; true,
		'publicly_queryable' =&gt; true,
		'exclude_from_search' =&gt; false,
		'supports' =&gt; array('title'/*,'editor','page-attributes','custom-fields','thumbnail','excerpt','comments'*/),
		'show_ui' =&gt; true,
		'rewrite' =&gt; array(
			'slug' =&gt; 'players',
			'with_front' =&gt; false
			),
		'has_archive' =&gt; 'players',
		'taxonomies' =&gt; array('leagues')
	) );
 
}

How to Query Custom Post Types

1
2
3
4
5
$args = array( 'post_type' =&gt; 'product', 'posts_per_page' =&gt; 10 );
$loop = new WP_Query( $args );
while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post();
	the_title();
	echo '
‘; the_content(); echo ‘
1
2
';
endwhile;

Useful Links

http://themergency.com/generators/wordpress-custom-post-types/
http://wordpress.org/extend/plugins/custom-post-type-ui/

March 18, 2013#

Back to Basics…

CSS (which stands for Cascading Style Sheets) is a language used to describe the appearance and formatting of your HTML.

A style sheet is a file that describes how an HTML file should look. That’s it!

Ways to Use CSS

  • External style sheet
  • Internal style sheet
  • Inline style

Ways to Include External Style Sheets

<link href="mystyle.css" rel="stylesheet" type="text/css" />
/* import stylesheets and hide from ie/mac \*/
@import url("reset.css");
@import url("master.css");
@import url("enriched.css");
@import url("ie.css");
/* end import/hide */

basic syntax

selector { property: value }

Example:

body {
     background-color: red;
}

classes, id’s, divs and spans

descendant selectors:

div div p {}

child selector:

div > p {}

adjacent sibling selector:

p + p { font-size: smaller; } /* Selects all paragraphs that follow another paragraph */
#title + ul { margin-top: 0; } /* Selects an unordered list that directly follows the element with ID title */

universal selector:

ul * {padding:0px; margin:0px}

group selector

p, strong, h2 {font-weight:bold}

Example HTML Code

<!DOCTYPE html> 
 
<html>
 
	<head>
 
		<meta charset="UTF-8" />
		<meta name="author" content="" />
		<meta name="copyright" content="" />
		<meta name="robots" content="index, follow" />
		<meta name="description" content="" />
		<meta name="keywords" content="" />
 
		<title></title>
 
		<link rel="Shortcut Icon" href="favicon.ico" type="image/x-icon" />
		<link rel="stylesheet" href="css/print.css" type="text/css" media="print" />
		<link rel="stylesheet" href="css/screen.css" type="text/css" media="screen,projection" />
		<link rel="index" title="" href="" />
 
		<!--[if lt IE 9 ]>
			<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
		<![endif]--> 
 
		<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
 
		<style type="text/css">
			body { 
				color: #222;
				font-family: helvetica, arial, sans-serif;
				font-size: 14px;
			}
 
			#content-wrapper {
				width: 960px;
				padding: 0;
				margin: 0 auto;
				border: 2px solid black;
			}
			#content-wrapper #left { 
				width: 25%;
				background: #E0E0E0;
				float: left;
			}
			#content-wrapper #content {
				width: 45%;
				float: left;
				padding: 0 2%;
				border: 1px solid red;
				border-top: 0;
			}
			#content-wrapper #right { 
				width: 25%;
				background: #000;
				color: #FFF;
				float: right;
			}
 
			#content p,
			#content li,
			#content a {
				color: green;
			}
 
			ul#last {
				list-style: none;
			}
			ul#last li { float: left; }
 
		</style>
	</head>
 
	<body class="" lang="en-US">
 
		<header id="primary-header">
 
			<nav id="primary-navigation">
				<ul>
					<li><a href="" title="">list <span>one</span></a></li>
					<li><a href="" title="">list <span>two</span></a></li>
				</ul>
			</nav>
 
		</header>
 
		<div id="content-wrapper">
 
			<aside id="left">
				<nav id="contextual-navigation">
					<ul>
						<li><a href="" title="">another list</a></li>
						<li><a href="" title="">another list</a></li>
					</ul>
				</nav>
			</aside>
 
			<section id="content">
				<p>content area</p>
				<p>content area</p>
				<p class="alternate">content area</p>
				<p>content area</p>
				<p>content area</p>
				<p>content area</p>
				<p>content area</p>
				<p class="end">content area</p>
 
				<div class="big">
					<div>
						<a href="">first link</a>
					</div>
				</div>
 
				<div>
					<div class="big">
						<a href="">second link</a>
					</div>
				</div>
 
				<div>
					<div>
						<a href="">third link</a>
					</div>
				</div>
 
 
				<ul>
				<li class="alternate">1st list item 1</li>
				<li>1st list item 2</li>
				<li class="end">1st list item 3</li>
				</ul>
 
				<ul id="last">
				<li>2nd list item 1</li>
				<li>2nd list item 2</li>
				<li class="end alternate">2nd list item 3</li>
				</ul>
			</section>
 
 
			<aside id="right">
				<p>Right Side content area</p>
			</aside>
			<br clear="both" />
		</div>
 
		<footer>
			footer
		</footer>
 
	</body>
 
</html>

Basic stuff…
http://www.cssbasics.com/
http://en.support.wordpress.com/custom-design/css-basics/

Advanced stuff…
http://coding.smashingmagazine.com/2009/08/17/taming-advanced-css-selectors/

March 4, 2013#

Grab This

<?php echo get_template_directory_uri(); ?>
<?php /* Start loop */ ?>
<?php while (have_posts()) : the_post(); ?>
      <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
      <?php the_content(); ?>
<?php endwhile; /* End the loop */ ?>
<?php echo "testing"; ?>
add_theme_support('post-thumbnails');
// set_post_thumbnail_size(150, 150, false);
 
// Add post formarts supports. http://codex.wordpress.org/Post_Formats
add_theme_support('post-formats', array('aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat'));
November 7, 2012#

Customizing the WordPress Backend

Not much explanation here, but I told one of my students that I would post up some code – so here it is…everything you need to get started customizing the admin area of WordPress

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* HIDE NAVIGATION AREAS IN ADMIN */
function remove_menus () {
	global $menu;
 
	// check if admin and hide these for admins
	if( (current_user_can('install_themes')) ) { 
		// $restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins')); 
		//$restricted = array(__('Dashboard'), __('Media'), __('Links'), __('Tools'), __('Users'), __('Settings'), __('Gallery'), __('Comments'), __('Plugins'));
	} else { // hide these for other roles
		//$restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins')); 
		$restricted = array(__('Dashboard')/*, __('Media')*/, __('Links'), __('Tools'), __('Users'), __('Settings'), __('Gallery'), __('Comments'), __('Plugins')); 
	}
 
	end ($menu);
 
	while (prev($menu)){
		$value = explode(' ',$menu[key($menu)][0]);
		if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
	}
}
add_action('admin_menu', 'remove_menus');
 
 
function customAdmin() {
    if( (current_user_can('install_themes')) ) { 
		$url = get_settings('siteurl');
	    $url = $url . '/wp-content/themes/soccer/css/wp-admin.css';
	    echo '<!-- custom admin css -->
	          <link rel="stylesheet" type="text/css" href="' . $url . '" />
	          <!-- /end custom adming css -->';
	} else { // hide these for other roles
		$url = get_settings('siteurl');
	    $url = $url . '/wp-content/themes/soccer/css/wp-admin.css';
	    echo '<!-- custom admin css -->
	          <link rel="stylesheet" type="text/css" href="' . $url . '" />
	          <!-- /end custom adming css -->'; 
	}
 
 
}
add_action('admin_head', 'customAdmin');
/* end: HIDE NAVIGATION AREAS IN ADMIN */
 
 
/* ADD CUSTOMIZED LOGIN STYLES */
function my_login_stylesheet() { 
	$url = get_settings('siteurl');
	$url = $url . '/wp-content/themes/soccer/css/wp-admin-login.css';
 
	 echo '<!-- custom admin css -->
	          <link rel="stylesheet" type="text/css" href="' . $url . '" />
	          <!-- /end custom adming css -->';
}
add_action( 'login_enqueue_scripts', 'my_login_stylesheet' );
/* end: ADD CUSTOMIZED LOGIN STYLES */
 
 
 
/* CUSTOMIZE DASHBOARD */
/*Custom Dashboard Widget*/
add_action('wp_dashboard_setup', 'add_instructions');
 
function add_instructions() {
	global $wp_meta_boxes;
	/*First, remove all stock, out of the box widgets*/
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
 
	unset($wp_meta_boxes['dashboard']['normal']['core']['wt_dashboard_statistics']);
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_custom_feed']);
 
 
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
 
	/*Now proceed to add our new widget*/
	wp_add_dashboard_widget('dashboard_instructions', 'Welcome to Active Youth Network', 'dashboard_instructions_widget');
}
 
function dashboard_instructions_widget() {
/*Add Our Custom Widget Code*/
?>
	<!--Put any html you want in here, you should use wordpress functions to get the url to your theme in order to include any images.-->
    <div id="ayn_dashboard">
    	<h1><?php bloginfo('name'); ?></h1>
    	<img src="<?php echo get_bloginfo('template_directory'); ?>/img/AYN-logo.png" style="float: left; margin: 0 20px 45px 0;" />
    	<h4 style="padding-top: 45px;">Keeping kids active in youth sports</h4>
    	<p>The Active Youth Network, LLC (AYN) is a Colorado based, national online ad network of youth sports websites that AYN markets t major brand, family-friendly advertisers who want to reach this premium audience. AYN is a cause related company that gives 70% of sales revenues generated back to its member clubs, schools and associations. AYN's mission is to help offset the escalating costs of participation to reduce the burden to families and keep kids active in youth sports. For more information go to <a href="http://www.activeyouthnetwork.com" target="_blank">www.activeyouthnetwork.com</a></p>
    	<br clear="both" />
    </div>	
	<!--End Html-->
<?php
}
 
 
// CUSTOM ADMIN DASHBOARD HEADER LOGO  
 
function custom_admin_logo(){  
    echo '<style type="text/css">#icon-index { background: url('.get_bloginfo('template_directory').'/images/AYN-logo-sm.png) no-repeat top left !important; }</style>';  
}  
add_action('admin_head', 'custom_admin_logo');
/* END: CUSTOMIZE DASHBOARD */
November 6, 2012#

Creating a WordPress Plugin

What is a plugin?

WordPress plugins are PHP scripts that alter your website. The changes could be anything from the simplest tweak in the header to a more drastic makeover (such as changing how log-ins work, triggering emails to be sent, and much more).

Whereas themes modify the look of your website, plugins change how it functions.

how do you make one?
All that is required is create a folder and then create a single file with one line of content. Navigate to the wp-content/plugins folder, and create a new folder named dummy_plugin. Inside this new folder, create a file named filename.php. Open the file in a text editor…

Basic Structure

1
2
3
4
5
6
7
8
9
10
<?php      
 /* 
   Plugin Name: Dummy Plugin 
   Plugin URI: http://www.hankis.me
   Description: A plugin that will set up custom post types
   Author: Hank Pantier
   Version: 1.0 
   Author URI: http://www.hankis.me 
   */ 
?>

What other files does a good plugin contain?

A readme file
This file gives information such as

  • Plugin Name
  • Description
  • Installation
  • Frequently Asked Questions
  • Screenshots
  • Changelog
  • Upgrade Notice
  • Arbitrary section
  • A brief Markdown Example

Here is an example.

License
Most Plugins use the GPL2 license used by WordPress or a license compatible with the GPL2. To indicate a GPL2 license, include the following lines in your Plugin:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php 
/*  Copyright YEAR  PLUGIN_AUTHOR_NAME  (email : PLUGIN AUTHOR EMAIL)     
This program is free software; you can redistribute it and/or modify     
it under the terms of the GNU General Public License, version 2, as      
published by the Free Software Foundation.     
 
This program is distributed in the hope that it will be useful,     
but WITHOUT ANY WARRANTY; without even the implied warranty of     
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     
GNU General Public License for more details.     
You should have received a copy of the GNU General Public License     
along with this program; if not, write to the Free Software     
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */ 
?>

After I have created a plugin, how do i make it “Work”

Actions
Actions are triggered by specific events that take place in WordPress, such as publishing a post, changing themes, or displaying a page of the admin panel.

Understanding add_action()
Actions target pre-defined areas in your templates and admin panel.

WordPress offers a comprehensive actions list in their API documentation. Below is a small list of example actions for you to get familiar with some of the pre-defined target areas.

  • publish_post – called when a post is published or when status is changed into “published”
  • save_post – called when a post/page is created from start or updated
  • wp_head – called when the template is loaded and runs the wp_head() function
  • loop_end – called immediately after the final post has been processed through the WordPress loop
  • trackback_post – called whenever a new trackback is added into a post
1
add_action('save_post', 'iW_other_function');

Filters
functions that WordPress passes data through, at certain points in execution, just before taking some action with the data (such as adding it to the database or sending it to the browser screen). Filters sit between the database and the browser (when WordPress is generating pages), and between the browser and the database (when WordPress is adding new posts and comments to the database)

Understanding add_filter()
Filters change text or data from WordPress – for example with a filter, we could change $the_content which is a variable set by WordPress containing the entire post content of a WordPress article.

1
add_filter('wp_title', 'iW_func');

A “Real World” Example

Hello Dolly

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
 * @package Hello_Dolly
 * @version 1.6
 */
/*
Plugin Name: Hello Dolly
Plugin URI: http://wordpress.org/extend/plugins/hello-dolly/
Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from <cite>Hello, Dolly</cite> in the upper right of your admin screen on every page.
Author: Matt Mullenweg
Version: 1.6
Author URI: http://ma.tt/
*/
 
function hello_dolly_get_lyric() {
	/** These are the lyrics to Hello Dolly */
	$lyrics = "Hello, Dolly
Well, hello, Dolly
It's so nice to have you back where you belong
You're lookin' swell, Dolly
I can tell, Dolly
You're still glowin', you're still crowin'
You're still goin' strong
We feel the room swayin'
While the band's playin'
One of your old favourite songs from way back when
So, take her wrap, fellas
Find her an empty lap, fellas
Dolly'll never go away again
Hello, Dolly
Well, hello, Dolly
It's so nice to have you back where you belong
You're lookin' swell, Dolly
I can tell, Dolly
You're still glowin', you're still crowin'
You're still goin' strong
We feel the room swayin'
While the band's playin'
One of your old favourite songs from way back when
Golly, gee, fellas
Find her a vacant knee, fellas
Dolly'll never go away
Dolly'll never go away
Dolly'll never go away again";
 
	// Here we split it into lines
	$lyrics = explode( "\n", $lyrics );
 
	// And then randomly choose a line
	return wptexturize( $lyrics[ mt_rand( 0, count( $lyrics ) - 1 ) ] );
}
 
// This just echoes the chosen line, we'll position it later
function hello_dolly() {
	$chosen = hello_dolly_get_lyric();
	echo "<p id='dolly'>$chosen</p>";
}
 
// Now we set that function up to execute when the admin_notices action is called
add_action( 'admin_notices', 'hello_dolly' );
 
// We need some CSS to position the paragraph
function dolly_css() {
	// This makes sure that the positioning is also good for right-to-left languages
	$x = is_rtl() ? 'left' : 'right';
 
	echo "
	<style type='text/css'>
	#dolly {
		float: $x;
		padding-$x: 15px;
		padding-top: 5px;		
		margin: 0;
		font-size: 11px;
	}
	</style>
	";
}
 
add_action( 'admin_head', 'dolly_css' );
 
?>

Making Your Own

Admin Screens

http://net.tutsplus.com/tutorials/wordpress/creating-a-custom-wordpress-plugin-from-scratch/

Some of my favorites

Advanced Custom Fields
Easy Content Types
Google Analytics for WordPress
Gravity Forms
NextGEN Gallery
Per Page Sidebars
Regenerate Thumbnails
WP Super Cache
WordPress SEO

Additional Resources

September 26, 2012#

Creative Code: WordPress Intro

installation/pitfalls/concepts

WordPress History
http://codex.wordpress.org/History
since: 2003

Features
Plugins / Themes / Hooks / Filters

Current Version 3.4.2
http://wordpress.org/

Requirements
(min) PHP 5.2.4 and MySQL 5.0.15 / Apache Mod Rewrite (for pretty permalinks)
what does this mean? how are they related?

Installing WordPress Locally
http://www.mamp.info/en/index.html
http://codex.wordpress.org/Installing_WordPress_Locally_on_Your_Mac_With_MAMP
http://wp.smashingmagazine.com/2011/09/28/developing-wordpress-locally-with-mamp/
http://wpcandy.com/teaches/how-to-install-wordpress-locally-on-a-mac

Software

HTML Editor
http://www.sublimetext.com/

FTP
http://filezilla-project.org/
http://cyberduck.ch/
http://panic.com/transmit/
http://fetchsoftworks.com/

WordPress config file
http://codex.wordpress.org/Editing_wp-config.php

1
2
3
4
5
6
7
8
9
10
11
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');
 
/** MySQL database username */
define('DB_USER', 'username_here');
 
/** MySQL database password */
define('DB_PASSWORD', 'password_here');
 
/** MySQL hostname */
define('DB_HOST', 'localhost');

Next time we meet we will be diving into how to create a theme and explore what a theme is comprised of. Also you will need to have your own URL and FTP server before we meet next. We will work on getting a version of WordPress up and running online so that you all can show off your mad WordPress skills to your friends.

I like Media Temple – here is a link – but don’t feel as if you have to use them.
Media Temple Grid Service Hosting

Light Reading

Using WordPress as a SAS platform http://www.dtelepathy.com/blog/dt-labs/wordpress-saas-application-platform
The SAS in question http://www.hellobar.com/

Zurb Foundation Documentation http://foundation.zurb.com/docs/http://foundation.zurb.com/docs/