<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WPreso &#124; WordPress Plugins and Themes</title>
	<atom:link href="http://www.wpreso.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wpreso.com</link>
	<description></description>
	<lastBuildDate>Fri, 08 Apr 2011 07:57:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Add multiple custom post types quickly and easily</title>
		<link>http://www.wpreso.com/blog/tutorials/2011/02/24/add-multiple-custom-post-types-quickly-and-easily/</link>
		<comments>http://www.wpreso.com/blog/tutorials/2011/02/24/add-multiple-custom-post-types-quickly-and-easily/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 06:18:31 +0000</pubDate>
		<dc:creator>WPreso</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.wpreso.com/?p=167</guid>
		<description><![CDATA[Here is a simple snippet of code to use when you want to add multiple custom post types and custom taxonomies to a theme or a plugin. Just add the values to the array and the custom post types and custom taxonomies will be added to your wordpress install. Works from wordpress 3.0+ &#60;?php /********************************* [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple snippet of code to use when you want to add multiple custom post types and custom taxonomies to a theme or a plugin. Just add the values to the array and the custom post types and custom taxonomies will be added to your wordpress install.</p>
<p>Works from wordpress 3.0+</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*********************************
  Quick &amp; Easy Custom Post Types
*********************************/</span>
<span style="color: #666666; font-style: italic;">/*
$cpts = array(
	'pt' =&gt; array( // unique value
		'post_type' =&gt; '', // post type name
		'supports' =&gt; array(''), // supports title, editor, author, comments etc. (optional, default: title, editor)
		'singular' =&gt; '', // post type singular label
		'plural' =&gt; '', // post type plural label
		'item_singular' =&gt; '', // post type singular item label (optional, if none is supplied, uses singular)
		'item_plural' =&gt; '', // post type plural item label (optional, if none is supplied, uses plural)
		'position' =&gt; '', // post type position in backend menu (optional, default: 20)
		'slug' =&gt; '', // post type slug
	)
);
&nbsp;
$ctaxs = array(
	'tx' =&gt; array(
		'taxonomy' =&gt; '', // taxonomy name
		'singular' =&gt; '', // taxonomy singular label
		'plural' =&gt; '', // taxonomy plural label
		'hierarchical' =&gt; '', // taxonomy hierarchical
		'slug' =&gt; '', // taxonomy slug
		'pts' =&gt; array('') // post types that are supported by the taxonomy
	)
)
&nbsp;
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/******************
POST TYPES
******************/</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpts</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso_custom_posttypes'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> wpreso_custom_posttypes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$cpts</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpts</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$cpt</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$item_singular_label</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'item_singular'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'item_singular'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>? <span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'item_singular'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$item_plural_label</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'item_plural'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'item_plural'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>? <span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'item_plural'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'plural'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$menu_position</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'position'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'position'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>? <span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'position'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span>  <span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$labels</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'plural'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'singular_name'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'add_new'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Add New'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'add_new_item'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Add New '</span><span style="color: #339933;">.</span><span style="color: #000088;">$item_singular_label</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'edit_item'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Edit '</span><span style="color: #339933;">.</span><span style="color: #000088;">$item_singular_label</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'new_item'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'New '</span><span style="color: #339933;">.</span><span style="color: #000088;">$item_singular_label</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'view_item'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'View '</span><span style="color: #339933;">.</span><span style="color: #000088;">$item_singular_label</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'search_items'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Search '</span><span style="color: #339933;">.</span><span style="color: #000088;">$item_plural_label</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'not_found'</span> <span style="color: #339933;">=&gt;</span>  __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No '</span><span style="color: #339933;">.</span><span style="color: #000088;">$item_plural_label</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' Found'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'not_found_in_trash'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No '</span><span style="color: #339933;">.</span><span style="color: #000088;">$item_plural_label</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' found in Trash'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'parent_item_colon'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$supports</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'supports'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'supports'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'supports'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>? <span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'supports'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'editor'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'labels'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$labels</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'public'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'publicly_queryable'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'map_meta_cap'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'rewrite'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'slug'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'slug'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'capability_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'hierarchical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'menu_position'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$menu_position</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'supports'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$supports</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		register_post_type<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'post_type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
	add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post_updated_messages'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso_posttype_updated_messages'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> wpreso_posttype_updated_messages<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$messages</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$cpts</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpts</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$cpt</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$messages</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'post_type'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #cc66cc;">0</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Unused. Messages start at index 1.</span>
			<span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span> __<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' Updated. &lt;a href=&quot;%s&quot;&gt;View '</span><span style="color: #339933;">.</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> esc_url<span style="color: #009900;">&#40;</span> get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_ID</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #cc66cc;">2</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Custom Field Updated.'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #cc66cc;">3</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Custom Field Deleted.'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #cc66cc;">4</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' Updated.'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #666666; font-style: italic;">/* translators: %s: date and time of the revision */</span>
			<span style="color: #cc66cc;">5</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'revision'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span> __<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' restored to revision from %s'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> wp_post_revision_title<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'revision'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
			<span style="color: #cc66cc;">6</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span> __<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' Published. &lt;a href=&quot;%s&quot;&gt;View '</span><span style="color: #339933;">.</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> esc_url<span style="color: #009900;">&#40;</span> get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_ID</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #cc66cc;">7</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' Saved.'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #cc66cc;">8</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span> __<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' Submitted. &lt;a target=&quot;_blank&quot; href=&quot;%s&quot;&gt;Preview '</span><span style="color: #339933;">.</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> esc_url<span style="color: #009900;">&#40;</span> add_query_arg<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'preview'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'true'</span><span style="color: #339933;">,</span> get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_ID</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #cc66cc;">9</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span> __<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' scheduled for: &lt;strong&gt;%1$s&lt;/strong&gt;. &lt;a target=&quot;_blank&quot; href=&quot;%2$s&quot;&gt;Preview '</span><span style="color: #339933;">.</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			  <span style="color: #666666; font-style: italic;">// translators: Publish box date format, see http://php.net/date</span>
			  date_i18n<span style="color: #009900;">&#40;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'d/m-Y @ H:i'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_date</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> esc_url<span style="color: #009900;">&#40;</span> get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_ID</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #cc66cc;">10</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span> __<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' Draft Updated. &lt;a target=&quot;_blank&quot; href=&quot;%s&quot;&gt;Preview '</span><span style="color: #339933;">.</span><span style="color: #000088;">$cpt</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> esc_url<span style="color: #009900;">&#40;</span> add_query_arg<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'preview'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'true'</span><span style="color: #339933;">,</span> get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_ID</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$messages</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/******************
TAXONOMIES
******************/</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ctaxs</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso_custom_taxonomies'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> wpreso_custom_taxonomies<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$ctaxs</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ctaxs</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$ct</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Add new taxonomy, make it hierarchical (like categories)</span>
		<span style="color: #000088;">$taxlabels</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$ct</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'plural'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'singular_name'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$ct</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'search_items'</span> <span style="color: #339933;">=&gt;</span>  __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Search '</span><span style="color: #339933;">.</span><span style="color: #000088;">$ct</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'plural'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'all_items'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'All '</span><span style="color: #339933;">.</span><span style="color: #000088;">$ct</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'plural'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'parent_item'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Parent '</span><span style="color: #339933;">.</span><span style="color: #000088;">$ct</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'parent_item_colon'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Parent '</span><span style="color: #339933;">.</span><span style="color: #000088;">$ct</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'edit_item'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Edit '</span><span style="color: #339933;">.</span><span style="color: #000088;">$ct</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'update_item'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Update '</span><span style="color: #339933;">.</span><span style="color: #000088;">$ct</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'add_new_item'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Add New '</span><span style="color: #339933;">.</span><span style="color: #000088;">$ct</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'new_item_name'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'New '</span><span style="color: #339933;">.</span><span style="color: #000088;">$ct</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'singular'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' name'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wpreso'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 	
&nbsp;
		register_taxonomy<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ct</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'taxonomy'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$ct</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pts'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'hierarchical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$ct</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'hierarchical'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'labels'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$taxlabels</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'show_ui'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'query_var'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'rewrite'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'slug'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$ct</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'slug'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.wpreso.com/blog/tutorials/2011/02/24/add-multiple-custom-post-types-quickly-and-easily/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add page/post slug class to menu item classes</title>
		<link>http://www.wpreso.com/blog/tutorials/2011/01/04/add-pagepost-slug-class-to-menu-item-classes/</link>
		<comments>http://www.wpreso.com/blog/tutorials/2011/01/04/add-pagepost-slug-class-to-menu-item-classes/#comments</comments>
		<pubDate>Tue, 04 Jan 2011 11:42:08 +0000</pubDate>
		<dc:creator>WPreso</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.wpreso.com/?p=158</guid>
		<description><![CDATA[I have not written anything for a long while, and before I had not written much as I am not really a blogger and I only write something when I actually have something that I want to share, which I do today. Once in a while you have to create a menu that has different [...]]]></description>
			<content:encoded><![CDATA[<p>I have not written anything for a long while, and before I had not written much as I am not really a blogger and I only write something when I actually have something that I want to share, which I do today.</p>
<p>Once in a while you have to create a menu that has different colors for each menu item. Now since the introduction of the menu builder in wordpress 3.0 or with one of the menu builder plugins like <a href="http://www.blogsweek.com/category/wordpress-menubar/" target="_blank">WP menubar</a>, you can add a class to each item. This though gets a bit tedious if you work on a local version of the site first and then have to update everything on a production version later.</p>
<p>Personally I think that the page/post slug should be part of the menu item classes instead of the menu item id number which less intuitive to use as classes in your style sheet, but it is probably a matter of taste.</p>
<p>Anyway, here is a filter that you can put in your functions.php to automatically add menu-item-slug, where slug in the page/post slug to the menu item classes, when you use the new WordPress menu system, wp_nav_menu. It also checks to see if you have a permalink structure and if it is not present, it will not add anything to your menu item classes.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> add_slug_class_to_menu_item<span style="color: #009900;">&#40;</span><span style="color: #000088;">$output</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$ps</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'permalink_structure'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ps</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$idstr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/&lt;li id=&quot;menu-item-(\d+)/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$output</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$mid</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$mid</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'_menu_item_object_id'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$slug</span> <span style="color: #339933;">=</span> <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span>get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/menu-item-'</span><span style="color: #339933;">.</span><span style="color: #000088;">$mid</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'menu-item-'</span><span style="color: #339933;">.</span><span style="color: #000088;">$mid</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' menu-item-'</span><span style="color: #339933;">.</span><span style="color: #000088;">$slug</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$output</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_nav_menu'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'add_slug_class_to_menu_item'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Thanks to <strong>Josh Stauffer</strong> for <a href="http://www.joshstauffer.com/get-post-slug-in-wordpress/">a great simple way to get the page/post slug</a>.<br />
Also thanks to these guys on the <strong>WP forums</strong> for explaining <a href="http://wordpress.org/support/topic/adding-a-class-to-first-and-last-menu-items">how to add filters to the menu items</a>. By the way, this is also a great resource if you want to add first/last classes to your menu items.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wpreso.com/blog/tutorials/2011/01/04/add-pagepost-slug-class-to-menu-item-classes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to dynamically add stylesheets to your wordpress theme</title>
		<link>http://www.wpreso.com/blog/tutorials/2009/10/14/how-to-dynamically-add-stylesheets-to-your-wordpress-theme/</link>
		<comments>http://www.wpreso.com/blog/tutorials/2009/10/14/how-to-dynamically-add-stylesheets-to-your-wordpress-theme/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 15:33:56 +0000</pubDate>
		<dc:creator>WPreso</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.wpreso.com/?p=130</guid>
		<description><![CDATA[If you use a lot of different stylesheets for your theme, it can get a little tedious to add them all to your header.php file. You could import them in your style.css, but some of the great minification plugins do not support import. If you organize all your stylesheets in a sub-folder in your theme, [...]]]></description>
			<content:encoded><![CDATA[<p>If you use a lot of different stylesheets for your theme, it can get a little tedious to add them all to your <em>header.php</em> file. You could import them in your <em>style.css</em>, but some of the great minification plugins do not support import.</p>
<p>If you organize all your stylesheets in a sub-folder in your theme, you can use the below function to automatically register and add them to your theme, provided that you use the <em>wp_head()</em> function in the head section of your <em>header.php</em>.</p>
<p><strong>Usage:</strong></p>
<ul>
<li>Add the below code to your functions.php file in your theme folder.</li>
<li>Add your stylesheets to a sub-folder named css.</li>
<li>You can add a print stylesheet, by calling it print.css, for a good starting point, try out <a href="http://code.google.com/p/hartija/">Hartija</a>.</li>
<li>For handheld devices, you can add a stylesheet called either iphone.css or handheld.css.</li>
<li>Lastly you can add a stylesheet for projection, and yes it should be called projection.css.</li>
<li>All the above stylesheets should be placed in the <em>CSS folder</em>.</li>
<li>If you want to use a different location for your stylesheets, you can change the location in the last part of the <em>themeCSSUrl</em> and <em>themeCSSDir</em> variables, to point to your desired location.</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_print_styles'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'add_stylesheets'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> add_stylesheets<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$themeCSSUrl</span> <span style="color: #339933;">=</span>  get_stylesheet_directory_uri<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/css/'</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$themeCSSDir</span> <span style="color: #339933;">=</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">'/css/'</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">opendir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$themeCSSDir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">readdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">end</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'css'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'print.css'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          wp_register_style<span style="color: #009900;">&#40;</span><span style="color: #990000;">current</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$themeCSSUrl</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'0.8'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'print'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          wp_enqueue_style<span style="color: #009900;">&#40;</span> <span style="color: #990000;">current</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'handheld.css'</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$file</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'iphone.css'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          wp_register_style<span style="color: #009900;">&#40;</span><span style="color: #990000;">current</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$themeCSSUrl</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'1.0'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'handheld'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          wp_enqueue_style<span style="color: #009900;">&#40;</span> <span style="color: #990000;">current</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'projection.css'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          wp_register_style<span style="color: #009900;">&#40;</span><span style="color: #990000;">current</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$themeCSSUrl</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'1.0'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'projection'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          wp_enqueue_style<span style="color: #009900;">&#40;</span> <span style="color: #990000;">current</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
          wp_register_style<span style="color: #009900;">&#40;</span><span style="color: #990000;">current</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$themeCSSUrl</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'1.0'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'screen'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          wp_enqueue_style<span style="color: #009900;">&#40;</span> <span style="color: #990000;">current</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>Update 8/4-2011</strong><br />
changed <code>get_bloginfo('template_url')</code> to <code>get_stylesheet_directory_uri()</code> to make this work for child themes as suggested by Paul.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wpreso.com/blog/tutorials/2009/10/14/how-to-dynamically-add-stylesheets-to-your-wordpress-theme/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WPreso Video Flow v0.3 released</title>
		<link>http://www.wpreso.com/blog/development/2009/10/01/wpreso-video-flow-v0-3-released/</link>
		<comments>http://www.wpreso.com/blog/development/2009/10/01/wpreso-video-flow-v0-3-released/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 16:51:15 +0000</pubDate>
		<dc:creator>WPreso</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Plugins]]></category>

		<guid isPermaLink="false">http://www.wpreso.com/?p=128</guid>
		<description><![CDATA[This fixes an error discovered by Jonas from ZORN D SIGN in which Video Flow tried to include a document from Video FeatureBox, so that if you did not have WPreso Video FeatureBox installed as well, it would crash your whole site.]]></description>
			<content:encoded><![CDATA[<p>This fixes an error discovered by <a href="http://www.blog.zorndsign.de/">Jonas from ZORN D SIGN</a> in which Video Flow tried to include a document from Video FeatureBox, so that if you did not have WPreso Video FeatureBox installed as well, it would crash your whole site.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wpreso.com/blog/development/2009/10/01/wpreso-video-flow-v0-3-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPreso Video plugins updated to version 0.2</title>
		<link>http://www.wpreso.com/blog/development/2009/09/30/wpreso-video-plugins-updated-to-version-0-2/</link>
		<comments>http://www.wpreso.com/blog/development/2009/09/30/wpreso-video-plugins-updated-to-version-0-2/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 23:06:32 +0000</pubDate>
		<dc:creator>WPreso</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Plugins]]></category>

		<guid isPermaLink="false">http://www.wpreso.com/?p=121</guid>
		<description><![CDATA[WPreso Video FeatureBox and WPreso Video Flow have been updated to version 0.2. The dependency on the deprecated function mime_content_type() has been removed. The function would check the mime type of the files in the plugin CSS directory and would then include the files which where CSS files. Due to the fact that the function [...]]]></description>
			<content:encoded><![CDATA[<p><strong>WPreso Video FeatureBox</strong> and <strong>WPreso Video Flow</strong> have been updated to <strong>version 0.2</strong>. </p>
<p>The dependency on the deprecated function mime_content_type() has been removed. </p>
<p>The function would check the mime type of the files in the plugin CSS directory and would then include the files which where CSS files. </p>
<p>Due to the fact that the function has been deprecated and some servers do not support the function, this validation has been removed. It now only checks the extension.</p>
<p>FileInfo might be used in the future, but as far as I have read, support for this could also be limited, so the best option is to wait until PHP 6 that should bring new built in support for file mime types.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wpreso.com/blog/development/2009/09/30/wpreso-video-plugins-updated-to-version-0-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WPreso Video Plugins released on WordPress.org Extend</title>
		<link>http://www.wpreso.com/blog/development/2009/09/16/wpreso-video-plugins-released-on-wordpress-org-extend/</link>
		<comments>http://www.wpreso.com/blog/development/2009/09/16/wpreso-video-plugins-released-on-wordpress-org-extend/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 19:35:59 +0000</pubDate>
		<dc:creator>WPreso</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Plugins]]></category>

		<guid isPermaLink="false">http://www.wpreso.com/?p=108</guid>
		<description><![CDATA[Today I released two of my plugins WPreso Video FeatureBox (and on wordpress.org) WPreso Video Flow (and on wordpress.org) This is the first time I have release a plugin to the public, so there might be some quirks that I will have to figure out along the way, but I hope people will enjoy them. [...]]]></description>
			<content:encoded><![CDATA[<p>Today I released two of my plugins</p>
<ul>
<li><a href="http://www.wpreso.com/plugins/wpreso-video-featurebox/">WPreso Video FeatureBox</a> (<a href="http://wordpress.org/extend/plugins/wpreso-video-featurebox/">and on wordpress.org</a>)</li>
<li><a href="http://www.wpreso.com/plugins/wpreso-video-flow/">WPreso Video Flow</a> (<a href="http://wordpress.org/extend/plugins/wpreso-video-flow/">and on wordpress.org</a>)</li>
</ul>
<p>This is the first time I have release a plugin to the public, so there might be some quirks that I will have to figure out along the way, but I hope people will enjoy them.</p>
<p>I will also be releasing another video plugin soon, which is called WPreso Video Carousel, you can already view in action on the showcase site <a href="http://www.wpvideotutorialsite.org">WPVideoTutorialSite.com</a>. It is a Video Carousel, but I will have more info on it in a later post and on its own plugin page, until then, I hope you enjoy these two.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wpreso.com/blog/development/2009/09/16/wpreso-video-plugins-released-on-wordpress-org-extend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Launch of WPreso.com</title>
		<link>http://www.wpreso.com/blog/2009/09/15/launch-of-wpreso-com/</link>
		<comments>http://www.wpreso.com/blog/2009/09/15/launch-of-wpreso-com/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 17:19:56 +0000</pubDate>
		<dc:creator>WPreso</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.wpreso.com/?p=93</guid>
		<description><![CDATA[WPreso launches with two WordPress plugins, WPreso Video FeatureBox and WPreso Video Flow, soon to be available on WordPress.org. More info on the plugins can be found on their respective pages: WPreso Video FeatureBox WPreso Video Flow or go to the plugins page. Hope you enjoy them.]]></description>
			<content:encoded><![CDATA[<p>WPreso launches with two WordPress plugins, WPreso Video FeatureBox and WPreso Video Flow, soon to be available on WordPress.org.</p>
<p>More info on the plugins can be found on their respective pages:</p>
<ul>
<li><a href="http://www.wpreso.com/plugins/wpreso-video-featurebox/">WPreso Video FeatureBox</a></li>
<li><a href="http://www.wpreso.com/plugins/wpreso-video-flow/">WPreso Video Flow</a></li>
</ul>
<p>or go to the <a href="http://www.wpreso.com/plugins/">plugins page</a>.</p>
<p>Hope you enjoy them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wpreso.com/blog/2009/09/15/launch-of-wpreso-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

