<?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>Pippin&#039;s Pages &#187; Tutorials</title> <atom:link href="http://pippinspages.com/category/tutorials/feed/" rel="self" type="application/rss+xml" /><link>http://pippinspages.com</link> <description>{ Coding everyday keeps the bugs away }</description> <lastBuildDate>Wed, 07 Dec 2011 22:09:26 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Add Scripts and Styles to Specific Admin Pages Only</title><link>http://pippinspages.com/tutorials/add-scripts-and-styles-to-specific-admin-pages-only/</link> <comments>http://pippinspages.com/tutorials/add-scripts-and-styles-to-specific-admin-pages-only/#comments</comments> <pubDate>Thu, 30 Jun 2011 20:33:54 +0000</pubDate> <dc:creator>Pippin Williamson</dc:creator> <category><![CDATA[jQuery]]></category> <category><![CDATA[Tutorials]]></category> <category><![CDATA[WordPress Tutorials]]></category> <category><![CDATA[CSS]]></category> <category><![CDATA[scripts]]></category> <category><![CDATA[wp tricks]]></category><guid isPermaLink="false">http://pippinspages.com/?p=2094</guid> <description><![CDATA[One very common mistake that is made by WordPress developers is failing to limit the environments in which their scripts are loaded, particularly in the admin section. For example, if you have written a plugin that has a settings page, &#8230; <a href="http://pippinspages.com/tutorials/add-scripts-and-styles-to-specific-admin-pages-only/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>One very common mistake that is made by WordPress developers is failing to limit the environments in which their scripts are loaded, particularly in the admin section.</p><p><span id="more-2094"></span></p><p> For example, if you have written a plugin that has a settings page, and that settings page requires a custom jquery script to be loaded, you should <em>always</em> ensure that the custom jquery script is <em>only</em> loaded when the settings page is displayed, not on every other page of the WordPress admin as well.</p><p>There are a couple of ways that you can limit which pages your scripts get loaded on, but by far the best method is to do it the way that WordPress intended <img src="http://pippinspages.com/wp-includes/images/smilies/icon_smile.gif?9707a5" alt=':)' class='wp-smiley' /></p><p>If you wanted to enable jQuery UI in the WordPress admin, you&#8217;d do it like this:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> load_ui_script<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	wp_enqueue_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery-ui.min'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1.4'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'all'</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> load_ui_style<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	wp_enqueue_style<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery-ui-css'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/base/jquery-ui.css'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1.8'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'all'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_print_scripts'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'load_ui_script'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_print_styles'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'load_ui_style'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>This works very well, but is not a good idea because if any other plugins (or the active theme) also load jQuery UI in the admin, there are likely to be conflicts.</p><p>So let&#8217;s say that you are trying to load jQuery-UI on <em>only</em> the post edit screen; you can do it like this:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> load_ui_script<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	wp_enqueue_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery-ui.min'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1.4'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'all'</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> load_ui_style<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	wp_enqueue_style<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery-ui-css'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/base/jquery-ui.css'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1.8'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'all'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_print_scripts-edit.php'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'load_ui_script'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_print_styles-edit.php'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'load_ui_style'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>Notice the <em>-edit.php</em> ? That tells WordPress to only activate the script on the edit post page. You can use any page slug there. So, for example, in my <a href="http://codecanyon.net/item/easy-custom-content-types-for-wordpress/234182?ref=mordauk">Easy Content Types plugin</a>, I used the following to add jQuery UI to the new post screen, the post edit screen, and the new custom post type screen:</p><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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> ecpt_datepicker_ui_scripts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	wp_enqueue_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery-ui.min'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1.4'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'all'</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> ecpt_datepicker_ui_style<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	wp_enqueue_style<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery-ui-css'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/base/jquery-ui.css'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1.8'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'all'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// load all the scripts</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_print_scripts-post.php'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ecpt_datepicker_ui_scripts'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_print_scripts-edit.php'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ecpt_datepicker_ui_scripts'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_print_scripts-post-new.php'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ecpt_datepicker_ui_scripts'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_print_styles-post.php'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ecpt_datepicker_ui_style'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_print_styles-post.php'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ecpt_datepicker_ui_style'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_print_styles-post-new.php'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ecpt_datepicker_ui_style'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_head'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ecpt_datepicker'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>You can also use this same method to load scripts on your custom plugin / theme settings pages.</p><p>Hope this helps.</p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://pippinspages.com/tutorials/font-size-controller-with-jquery/">Font Size Controller with jQuery</a> <span class="related-post-date timestamp">Thu 24 Feb 2011</span></li><li class="related-post"><a href="http://pippinspages.com/wordpress/sugar-slider-wordpress-sliders-manager/">Sugar Slider – WordPress Sliders Manager</a> <span class="related-post-date timestamp">Sun 06 Feb 2011</span></li><li class="related-post"><a href="http://pippinspages.com/tutorials/jquery-tricks-for-developers-trying-to-satisfy-designers/">jQuery Tricks for Developers Trying to Satisfy Designers</a> <span class="related-post-date timestamp">Mon 15 Nov 2010</span></li></ul>]]></content:encoded> <wfw:commentRss>http://pippinspages.com/tutorials/add-scripts-and-styles-to-specific-admin-pages-only/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>Slick, CSS 3 Image Drop Shadows</title><link>http://pippinspages.com/tutorials/css/slick-css-3-image-drop-shadows/</link> <comments>http://pippinspages.com/tutorials/css/slick-css-3-image-drop-shadows/#comments</comments> <pubDate>Mon, 18 Apr 2011 14:00:02 +0000</pubDate> <dc:creator>Pippin Williamson</dc:creator> <category><![CDATA[CSS]]></category> <category><![CDATA[Design]]></category> <category><![CDATA[Tutorials]]></category> <category><![CDATA[css3]]></category> <category><![CDATA[drop shadows]]></category><guid isPermaLink="false">http://pippinspages.com/?p=1992</guid> <description><![CDATA[Today, while working on a theme update for my buddy AJ Clark, of WP Explorer, I cooked up some sick CSS 3 only drop shadows. The shadow on the image below is what we will be creating, with only CSS: &#8230; <a href="http://pippinspages.com/tutorials/css/slick-css-3-image-drop-shadows/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>Today, while working on a theme update for my buddy AJ Clark, of <a href="http://www.mojo-themes.com/item/cleaner-business-wordpress-theme/?r=pippin">WP Explorer</a>, I cooked up some sick CSS 3 only drop shadows.<br /> <span id="more-1992"></span><br /> The shadow on the image below is what we will be creating, with only CSS:</p><p><a href="http://pippinspages.com/wp-content/uploads/2011/04/css3-shadow.png?9707a5"><img src="http://pippinspages.com/wp-content/uploads/2011/04/css3-shadow.png?9707a5" alt="" title="css3-shadow" width="421" height="267" class="alignnone size-full wp-image-1993" /></a></p><p>The first step is to set up your HTML structure:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image-wrap&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image-thumb&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;path/to/your/image.jpg&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image-shadow&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div><p>Next, some basic CSS:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.image-wrap</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.image-thumb</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">180px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/*set this to the size of your image*/</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">280px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/*set this to the size of your image*/</span>
	<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div><p>The next step is a little more complex and utilizes the :before and :after pseudo selectors to allow us to do super cool stuff <img src="http://pippinspages.com/wp-includes/images/smilies/icon_smile.gif?9707a5" alt=':)' class='wp-smiley' /></p><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
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.thumb-shadow</span>	<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">180px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/*this must be the same as declared above*/</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">280px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/*this must be the same as declared above*/</span>
	<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #808080; font-style: italic;">/*shadow*/</span>
<span style="color: #6666ff;">.image-shadow</span><span style="color: #3333ff;">:after </span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">''</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#828282</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">98%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">3px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> -<span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
	-webkit-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>2deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	box-shadow<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">2px</span> <span style="color: #933;">5px</span> <span style="color: #cc00cc;">#828282</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.image-shadow</span><span style="color: #3333ff;">:before </span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">''</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#828282</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">95%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">3px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> -<span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
	-webkit-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>-2deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	box-shadow<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">2px</span> <span style="color: #933;">5px</span> <span style="color: #cc00cc;">#828282</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #808080; font-style: italic;">/*end shadow*/</span></pre></td></tr></table></div><p>What we have done created two gray &#8220;stripes&#8221; that are slightly blurred, and then rotated them slightly to give the impression of a curved shadow. Pretty cool, huh?</p><p>This is a pretty simple application of this technique, and you could go much further and create more intricate shadows if you wanted.</p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://pippinspages.com/tutorials/css/freebie-css-3-drop-down-menus/">Freebie - CSS 3 Drop Down Menus</a> <span class="related-post-date timestamp">Tue 22 Jun 2010</span></li></ul>]]></content:encoded> <wfw:commentRss>http://pippinspages.com/tutorials/css/slick-css-3-image-drop-shadows/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>Pass Parameters to query_posts and Keep Query Intact</title><link>http://pippinspages.com/tutorials/pass-parameters-to-query_posts-and-keep-query-intact/</link> <comments>http://pippinspages.com/tutorials/pass-parameters-to-query_posts-and-keep-query-intact/#comments</comments> <pubDate>Sat, 16 Apr 2011 01:41:16 +0000</pubDate> <dc:creator>Pippin Williamson</dc:creator> <category><![CDATA[Tutorials]]></category> <category><![CDATA[Wordpress]]></category> <category><![CDATA[WordPress Tutorials]]></category> <category><![CDATA[custom query]]></category> <category><![CDATA[query_posts]]></category><guid isPermaLink="false">http://pippinspages.com/?p=1986</guid> <description><![CDATA[When working with custom queries, as is quite common in theme development, you will often need to pass certain parameters to the query_posts() function, such as those to limit the category or the number of posts displayed. The problem with &#8230; <a href="http://pippinspages.com/tutorials/pass-parameters-to-query_posts-and-keep-query-intact/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>When working with custom queries, as is quite common in theme development, you will often need to pass certain parameters to the query_posts() function, such as those to limit the category or the number of posts displayed. <span id="more-1986"></span>The problem with doing this is that the moment you pass a parameter to query_posts(), it causes the function to ignore all default parameters. This causes a problem, for example, when you have created a custom archive.php (or other template) and you attempt to view the archive for a date range or category. What will happen in this case, is that the category or date parameters passed to WordPress will be ignored, such all dates and or categories will be displayed, not just the ones you tried to limit it to. So you&#8217;re stuck. The custom parameters you passed to query_posts() are useless because they break everything else.</p><p>Luckily, there&#8217;s an easy fix to the above scenario.</p><p>All of the query parameters passed by WordPress are stored in a global variable called <em>$query_string</em>. So, let&#8217;s say you have a query like this:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cat=5&amp;posts_per_page=6'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>If that&#8217;s in an archive loop, the archive will break, so, to fix it, do this instead:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$query_string</span><span style="color: #339933;">;</span>
query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cat=5&amp;posts_per_page=6&amp;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$query_string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>This will cause query_posts() to recognize all of the parameters passed from WordPress, <em>as well as</em> all of those you have chosen to pass manually.</p><p>Hope this helps!</p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"></ul>]]></content:encoded> <wfw:commentRss>http://pippinspages.com/tutorials/pass-parameters-to-query_posts-and-keep-query-intact/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Fix Broken Search Pagination in WordPress 3.1</title><link>http://pippinspages.com/tutorials/fix-broken-search-pagination-in-wordpress-3-1/</link> <comments>http://pippinspages.com/tutorials/fix-broken-search-pagination-in-wordpress-3-1/#comments</comments> <pubDate>Sat, 05 Mar 2011 01:19:55 +0000</pubDate> <dc:creator>Pippin Williamson</dc:creator> <category><![CDATA[Tutorials]]></category> <category><![CDATA[Wordpress]]></category> <category><![CDATA[WordPress Tutorials]]></category> <category><![CDATA[pagination]]></category> <category><![CDATA[permalinks]]></category> <category><![CDATA[search]]></category><guid isPermaLink="false">http://pippinspages.com/?p=1949</guid> <description><![CDATA[This morning I spent several hours debugging a broken WordPress search pagination. The function itself worked fine, but when clicking over to any page, a 404 error was displayed. Unlike the usual culprit, a custom query_posts() function was not the &#8230; <a href="http://pippinspages.com/tutorials/fix-broken-search-pagination-in-wordpress-3-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>This morning I spent several hours debugging a broken WordPress search pagination. The function itself worked fine, but when clicking over to any page, a 404 error was displayed. Unlike the usual culprit, a custom query_posts() function was not the problem here.<br /> <span id="more-1949"></span><br /> After staring blankly at line after line of code, deleting random snippets, and doing everything else I could think of to try and locate the problem, I noticed something strange: when hovering over the pagination links, the page URLs looked like this:</p><pre>http://site.com/blog/blog/page/2?s=searchphrase</pre><p>when it should have been:</p><pre>http://site.com/blog/page/2?s=searchphrase</pre><p>Notice the second &#8220;blog&#8221; in there?</p><p>Finally, I tried reverting back to the default search form by removing searchform.php from my theme directory. There! I found it. The problem was fixed. But I really needed and wanted my custom searchform.php. So what was the problem?</p><p>Well, looking at the Codex entry for <em><a href="http://codex.wordpress.org/Function_Reference/get_search_form">get_search_form()</a></em>, I saw that the default search form layout was:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> role<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;search&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;get&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;searchform&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?php echo home_url( '/' ); ?&gt;</span></span>&quot;&gt;
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen-reader-text&quot;</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;s&quot;</span>&gt;</span>Search for:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;s&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;s&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;searchsubmit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Search&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></td></tr></table></div><p>and mine was:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> role<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;search&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;get&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;searchform&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?php bloginfo('url'); ?&gt;</span></span>&quot;&gt;
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen-reader-text&quot;</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;s&quot;</span>&gt;</span>Search for:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;s&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;s&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;searchsubmit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Search&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></td></tr></table></div><p>See the problem? It&#8217;s not obvious, but the problem is caused by <em>bloginfo(&#8216;url&#8217;);</em> being used for the action=&#8221;" parameter of the FORM tag, instead of <em>echo home_url();</em>.</p><p>I am not exactly sure why <em>bloginfo(&#8216;url&#8217;)</em> is different from <em>echo home_url();</em> because they both display exactly the same thing. But it <em>does</em> fix the problem.</p><p>Hopefully this will solve someone else&#8217;s trouble before you spend hours and hours on it as I did.</p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"></ul>]]></content:encoded> <wfw:commentRss>http://pippinspages.com/tutorials/fix-broken-search-pagination-in-wordpress-3-1/feed/</wfw:commentRss> <slash:comments>10</slash:comments> </item> <item><title>Get Category Name from ID</title><link>http://pippinspages.com/tutorials/get-category-name-from-id/</link> <comments>http://pippinspages.com/tutorials/get-category-name-from-id/#comments</comments> <pubDate>Tue, 01 Mar 2011 21:38:53 +0000</pubDate> <dc:creator>Pippin Williamson</dc:creator> <category><![CDATA[Tutorials]]></category> <category><![CDATA[Wordpress]]></category> <category><![CDATA[WordPress Tutorials]]></category> <category><![CDATA[cat id]]></category> <category><![CDATA[category]]></category> <category><![CDATA[category name]]></category><guid isPermaLink="false">http://pippinspages.com/?p=1942</guid> <description><![CDATA[WordPress has a nice little function get_cat_name() that allows us to retrieve the name of the category from the database by using the ID of the desired category. For example, you have a category with an ID of 12, and &#8230; <a href="http://pippinspages.com/tutorials/get-category-name-from-id/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>WordPress has a nice little function <em>get_cat_name()</em> that allows us to retrieve the name of the category from the database by using the ID of the desired category.<br /> <span id="more-1942"></span><br /> For example, you have a category with an ID of 12, and you want to echo the name of that category. You can it like this:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$category_id</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">12</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//replace with your category ID</span>
<span style="color: #b1b100;">echo</span> get_cat_name<span style="color: #009900;">&#40;</span><span style="color: #000088;">$category_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>This is particular useful in cases, such as them option panels, where a user has enter ID numbers of categories, and you need to get the name of those categories.</p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"></ul>]]></content:encoded> <wfw:commentRss>http://pippinspages.com/tutorials/get-category-name-from-id/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Get Featured Thumbnail URL</title><link>http://pippinspages.com/tutorials/get-featured-thumbnail-url/</link> <comments>http://pippinspages.com/tutorials/get-featured-thumbnail-url/#comments</comments> <pubDate>Fri, 25 Feb 2011 16:00:57 +0000</pubDate> <dc:creator>Pippin Williamson</dc:creator> <category><![CDATA[Tutorials]]></category> <category><![CDATA[Wordpress]]></category> <category><![CDATA[WordPress Tutorials]]></category> <category><![CDATA[post image]]></category> <category><![CDATA[the_post_thumbnail]]></category><guid isPermaLink="false">http://pippinspages.com/?p=1936</guid> <description><![CDATA[A lot of times it can be necessary to be able to obtain just the source URL of a post&#8217;s featured thumbnail. Using the wp_get_attachment_image_src() function, we can obtain the URL of whatever image size we want: 1 2 3 &#8230; <a href="http://pippinspages.com/tutorials/get-featured-thumbnail-url/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>A lot of times it can be necessary to be able to obtain just the source URL of a post&#8217;s featured thumbnail.</p><p>Using the <em>wp_get_attachment_image_src()</em> function, we can obtain the URL of whatever image size we want:<br /> <span id="more-1936"></span></p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// store the image URL in an array</span>
<span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> wp_get_attachment_image_src<span style="color: #009900;">&#40;</span> get_post_thumbnail_id<span style="color: #009900;">&#40;</span>  <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;thumbnail-size&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// output the URL</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$image</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>You can choose to display whatever size of image you want by altering the &#8220;thumbnail-size&#8221; parameter. It can be any size you have declared in your functions.php with <a href="http://codex.wordpress.org/Function_Reference/add_image_size">add_image_size()</a>, or it can be an array, like this:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> wp_get_attachment_image_src<span style="color: #009900;">&#40;</span> get_post_thumbnail_id<span style="color: #009900;">&#40;</span>  <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">400</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">350</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"></ul>]]></content:encoded> <wfw:commentRss>http://pippinspages.com/tutorials/get-featured-thumbnail-url/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Font Size Controller with jQuery</title><link>http://pippinspages.com/tutorials/font-size-controller-with-jquery/</link> <comments>http://pippinspages.com/tutorials/font-size-controller-with-jquery/#comments</comments> <pubDate>Fri, 25 Feb 2011 02:48:42 +0000</pubDate> <dc:creator>Pippin Williamson</dc:creator> <category><![CDATA[jQuery]]></category> <category><![CDATA[Tutorials]]></category> <category><![CDATA[font size]]></category> <category><![CDATA[fonts]]></category><guid isPermaLink="false">http://pippinspages.com/?p=1930</guid> <description><![CDATA[For accessibility reasons, a lot of websites, particularly those that have an elderly audience, include a font size controller that allows visitors to increase or decrease the page&#8217;s font size for better readability. A client&#8217;s site I was working on &#8230; <a href="http://pippinspages.com/tutorials/font-size-controller-with-jquery/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>For accessibility reasons, a lot of websites, particularly those that have an elderly audience, include a font size controller that allows visitors to increase or decrease the page&#8217;s font size for better readability.<br /> <span id="more-1930"></span><br /> A client&#8217;s site I was working on needed that exact functionality today. In the past I&#8217;ve always used some common javascripts to achieve the functionality. But today I decided to do it with jQuery.</p><p>This is a really simple, and by no means a fully polished method of building a font size controller. Depending on your requirements though, this may work as perfectly for you as it did for me.</p><p>First, layout some basic HTML:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;small&quot;</span>&gt;</span>A <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;medium&quot;</span>&gt;</span>B <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;large&quot;</span>&gt;</span>C<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre></td></tr></table></div><p>Our controller now looks something like this:</p><p><span style="font-size: 16px;">A</span> <span style="font-size: 19px;">B</span> <span style="font-size:22px;">C</span></p><p>Then some basic CSS:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#small</span>	<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#medium</span>	<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">19px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#large</span>	<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">22px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div><p>Lastly, we add a little jQuery to make the magic happen.</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$j<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#small'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$j<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body p'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fontSize'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'12px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$j<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#medium'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$j<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body p'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fontSize'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'14px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$j<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#large'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$j<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body p'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fontSize'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'18px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>Now, whenever any of the font size controls are clicked in our controller, all of the Paragraph tabs on our site will have their font changed to the specified pixel size. Simple, yet effective.</p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://pippinspages.com/tutorials/add-scripts-and-styles-to-specific-admin-pages-only/">Add Scripts and Styles to Specific Admin Pages Only</a> <span class="related-post-date timestamp">Thu 30 Jun 2011</span></li><li class="related-post"><a href="http://pippinspages.com/wordpress/give-away-3-free-copies-of-font-uploader-for-wordpress/">Give Away: 3 Free Copies of Font Uploader for WordPress</a> <span class="related-post-date timestamp">Mon 02 May 2011</span></li><li class="related-post"><a href="http://pippinspages.com/wordpress/sugar-slider-wordpress-sliders-manager/">Sugar Slider – WordPress Sliders Manager</a> <span class="related-post-date timestamp">Sun 06 Feb 2011</span></li></ul>]]></content:encoded> <wfw:commentRss>http://pippinspages.com/tutorials/font-size-controller-with-jquery/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>jQuery Tricks for Developers Trying to Satisfy Designers</title><link>http://pippinspages.com/tutorials/jquery-tricks-for-developers-trying-to-satisfy-designers/</link> <comments>http://pippinspages.com/tutorials/jquery-tricks-for-developers-trying-to-satisfy-designers/#comments</comments> <pubDate>Mon, 15 Nov 2010 15:00:17 +0000</pubDate> <dc:creator>Pippin Williamson</dc:creator> <category><![CDATA[jQuery]]></category> <category><![CDATA[Tutorials]]></category> <category><![CDATA[jquery tips]]></category><guid isPermaLink="false">http://pippinspages.com/?p=1668</guid> <description><![CDATA[As a developer who considers himself a pseudo-designer, I know the struggles a developer encounters far too often when trying to satisfy the desires of a designer. I need those columns to be the same height. ALWAYS I only want &#8230; <a href="http://pippinspages.com/tutorials/jquery-tricks-for-developers-trying-to-satisfy-designers/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>As a developer who considers himself a pseudo-designer, I know the struggles a developer encounters far too often when trying to satisfy the desires of a designer.<br /> <span id="more-1668"></span></p><blockquote><p>I need those columns to be the same height. ALWAYS</p></blockquote><blockquote><p>I only want that arrow there when there&#8217;s a sub menu</p></blockquote><blockquote><p>Every browser must be supported, including IE 6! For ALL effects!</p></blockquote><p>The list of common demands goes on and on (makes you kind of wish everyone used green text-only consoles still . . . ).</p><p>This post is a list of jQuery tools for developers trying to appease their designer overlords.</p><h3>Use Your Own Image Bullets</h3><p>This simple snippet will let you use whatever you want, such as text or images for list bullets.</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Replaced&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul &gt; li&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prepend</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;‒ &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// use dashes for bullets</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>If you wanted to use an image, you could use this instead:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Replaced&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul &gt; li&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prepend</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;img src='path-to-your-image'/&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// use a custom image</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>Then just make sure you have a class like this</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"> ul<span style="color: #6666ff;">.Replaced</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">list-style</span> <span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div><p>to remove the default bullets.</p><h3>Cross Browser Opacity</h3><p>Making an element transparent can be accomplished using only CSS, but requires about five lines of code. With jQuery, we can achieve transparency with just one line:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.element&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;opacity&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0.5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><h3>Text-Shadows in IE</h3><p>CSS 3 brought us the wonderful text-shadow property, but, as usual, it&#8217;s not supported in IE. So, if your designer insists that text shadows must be present in IE as well, then you can use this nifty little plugin from <a href="http://kilianvalkhof.com/2008/javascript/text-shadow-in-ie-with-jquery/">Kilian Valkhof</a>.</p><p>To enable text-shadows in IE, your code looks like this:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>.<span style="color: #660066;">element</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">textShadow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	color<span style="color: #339933;">:</span>   <span style="color: #3366CC;">&quot;#000&quot;</span><span style="color: #339933;">,</span>
	xoffset<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;5px&quot;</span><span style="color: #339933;">,</span>
	yoffset<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;5px&quot;</span><span style="color: #339933;">,</span>
	radius<span style="color: #339933;">:</span>  <span style="color: #3366CC;">&quot;5px&quot;</span><span style="color: #339933;">,</span>
	opacity<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;50&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p><a class="downloadlink" href="http://pippinspages.com/wp-content/plugins/download-monitor/download.php?id=9" title=" downloaded 137 times" >jQuery Text Shadows (137)</a></p><h3>Make Columns Equal Heights</h3><p>If you&#8217;re working with a multi-column layout, it can be extremely useful to make those automatically resize so that their heights are matched.</p><p>The jQuery looks like this:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.columns&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">equalHeights</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span><span style="color: #CC0000;">300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Min height of 100. Max height of 300</span></pre></td></tr></table></div><p>This will set any element of the class &#8220;columns&#8221; to a minimum height of 100 pixels, and a maximum height of 300 pixels. If the content causes an element to grow larger than 300 pixels, a scrollbar will be added.</p><p>You can check out the plugin page at <a href="http://www.cssnewbie.com/equalheights-jquery-plugin/">CSS Newbie</a> or download directly below:</p><p><a class="downloadlink" href="http://pippinspages.com/wp-content/plugins/download-monitor/download.php?id=10" title=" downloaded 133 times" >jQuery Equal Heights (133)</a></p><h3>Add Arrows to LIs with Nested ULs</h3><p>If you&#8217;ve ever made a multi-level drop down menu in something like WordPress where all the ULs and LIs are generated for you, you&#8217;ll know that it can be very difficult to add such simple effects as arrow indicators to all the LIs that contain a nested UL, without also giving arrows to the LIs without ULs.</p><p>This simple jQuery trick, demonstrated to me by <a href="http://www.problogdesign.com/">Michael Martin</a>, will automatically add a special &#8220;has-sub-menu&#8221; class to all your LI&#8217;s with nested ULs.</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$j<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.menu &gt; li &gt; ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'has-sub-menu'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>Then you just style accordingly:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.menu</span> <span style="color: #00AA00;">&gt;</span> li<span style="color: #6666ff;">.has-sub-menu</span>	<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'../images/triangle.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #933;">80px</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div><p>If you have a multi-leveled menu, with say a sub menu within a sub menu, you can us this to add a different triangle to the 2nd level sub menu:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$j<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.menu li ul li ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'sub-sub-menu'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><h3>Add Pseudo Selector Support to IE</h3><p>Pseudo selectors in CSS are one of a developers best friends, except when IE gets involved. So, in order to rectify that small grievance, you can use the <a href="http://skulljackpot.com/2009/04/19/super-css-selector-support-with-jquery/">SuperSelectors </a>jQuery plugin to add support for pseudo selectors to IE. And it can be used like this:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">superSelectify</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>That will give support for all pseudo selectors, using special class names. Read more about it on <a href="http://skulljackpot.com/2009/04/19/super-css-selector-support-with-jquery/">Skull Jackpot</a>.</p><p>That&#8217;s it for now, enjoy!</p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://pippinspages.com/tutorials/add-scripts-and-styles-to-specific-admin-pages-only/">Add Scripts and Styles to Specific Admin Pages Only</a> <span class="related-post-date timestamp">Thu 30 Jun 2011</span></li><li class="related-post"><a href="http://pippinspages.com/tutorials/font-size-controller-with-jquery/">Font Size Controller with jQuery</a> <span class="related-post-date timestamp">Thu 24 Feb 2011</span></li><li class="related-post"><a href="http://pippinspages.com/wordpress/sugar-slider-wordpress-sliders-manager/">Sugar Slider – WordPress Sliders Manager</a> <span class="related-post-date timestamp">Sun 06 Feb 2011</span></li></ul>]]></content:encoded> <wfw:commentRss>http://pippinspages.com/tutorials/jquery-tricks-for-developers-trying-to-satisfy-designers/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Get Page ID by Page Name</title><link>http://pippinspages.com/tutorials/get-page-id-by-page-name/</link> <comments>http://pippinspages.com/tutorials/get-page-id-by-page-name/#comments</comments> <pubDate>Fri, 15 Oct 2010 23:12:28 +0000</pubDate> <dc:creator>Pippin Williamson</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[Tutorials]]></category> <category><![CDATA[Wordpress]]></category> <category><![CDATA[WordPress Tutorials]]></category> <category><![CDATA[tips]]></category> <category><![CDATA[tutorial]]></category> <category><![CDATA[wp tricks]]></category><guid isPermaLink="false">http://pippinspages.com/?p=1661</guid> <description><![CDATA[This is a wonderful little function was written by Web-Templates.nu, and allows you to find the ID of a page by using its name. This can be extremely useful for a variety of scenarios. For example, if you have ever &#8230; <a href="http://pippinspages.com/tutorials/get-page-id-by-page-name/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>This is a wonderful little function was written by <a href="http://www.web-templates.nu/2008/09/02/get-id-by-page-name/">Web-Templates.nu</a>, and allows you to find the ID of a page by using its name.<br /> <span id="more-1661"></span><br /> This can be extremely useful for a variety of scenarios. For example, if you have ever wanted to list the subpages of a particular page using something like this</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'child_of=10'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>where <strong>10</strong> is the page ID, you have probably run into the problem of how to prevent this from breaking if the ID of the page ever changes, but the name is kept the same.</p><p>Well with this function, you can do this:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$page_id</span> <span style="color: #339933;">=</span> wt_get_ID_by_page_name<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'PageName'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'child_of='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$page_ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>All you need to do is paste the function in your functions.php:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> wt_get_ID_by_page_name<span style="color: #009900;">&#40;</span><span style="color: #000088;">$page_name</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;">$wpdb</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$page_name_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_var</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT ID FROM <span style="color: #006699; font-weight: bold;">$wpdb-&gt;posts</span> WHERE post_name = '&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$page_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$page_name_id</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://pippinspages.com/tutorials/wordpress-cms-tips-and-tricks-part-3/">Wordpress CMS Tips and Tricks - Part 3</a> <span class="related-post-date timestamp">Wed 19 May 2010</span></li><li class="related-post"><a href="http://pippinspages.com/tutorials/check-if-current-page-is-in-tree/">Check if Current Page is in Tree</a> <span class="related-post-date timestamp">Wed 08 Sep 2010</span></li><li class="related-post"><a href="http://pippinspages.com/tutorials/css/quick-tip-remove-right-margin-from-column-post-layout-with-php/">Quick Tip: Remove right margin from column post layout with php</a> <span class="related-post-date timestamp">Sat 08 May 2010</span></li></ul>]]></content:encoded> <wfw:commentRss>http://pippinspages.com/tutorials/get-page-id-by-page-name/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Publish Action Hook for Custom Post Types</title><link>http://pippinspages.com/tutorials/publish-action-hook-for-custom-post-types/</link> <comments>http://pippinspages.com/tutorials/publish-action-hook-for-custom-post-types/#comments</comments> <pubDate>Thu, 30 Sep 2010 13:15:32 +0000</pubDate> <dc:creator>Pippin Williamson</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[Tutorials]]></category> <category><![CDATA[Wordpress]]></category> <category><![CDATA[WordPress Tutorials]]></category> <category><![CDATA[action hooks]]></category> <category><![CDATA[add_action]]></category> <category><![CDATA[announcements]]></category> <category><![CDATA[code canyon]]></category> <category><![CDATA[custom post types]]></category> <category><![CDATA[publish_post]]></category><guid isPermaLink="false">http://pippinspages.com/?p=1624</guid> <description><![CDATA[Most of the time, when a developer wants to make something happen every time a post is published, such as send out an email notification, they use 1 add_action&#40;'publish_post', 'the_function_to_perform'&#41;; This works great, but with one, major problem: it doesn&#8217;t &#8230; <a href="http://pippinspages.com/tutorials/publish-action-hook-for-custom-post-types/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>Most of the time, when a developer wants to make something happen every time a post is published, <a href="http://www.wprecipes.com/how-to-automatically-notify-your-members-on-new-posts">such as send out an email notification</a>, they use<br /> <span id="more-1624"></span></p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'publish_post'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'the_function_to_perform'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>This works great, but with one, major problem: it doesn&#8217;t work for <strong>custom post types</strong>.</p><p>While working on an update to my <a href="http://codecanyon.net/item/premium-wordpress-announcements-plugin/113296?ref=mordauk">WordPress Announcements plugin</a>, I ran into a problem because <em>publish_post</em> did not work for my custom post type. After several hours of digging, I came across this: <strong><a href="http://adambrown.info/p/wp_hooks/hook/%7B$new_status%7D_%7B$post-%3Epost_type%7D">{$new_status}_{$post->post_type}</a></strong>, and it did exactly what I wanted it to do: perform an action every time a certain custom post type is published.</p><p>It works like this:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'publish_custom_post_type_name'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'function_to_perform'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>where &#8220;custom_post_type_name&#8221; is the name of your custom post type. So if you have a post type of &#8220;music&#8221;, your hook would like this:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'publish_music'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'function_to_perform'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>Perfect!</p><p>This allowed me to do exactly what I needed to do for my plugin update. So what is this update? Well, I&#8217;m not going to come straight out and tell you, except to say that it has to do with really cool announcement notifications. You should check out the <a href="http://codecanyon.net/item/premium-wordpress-announcements-plugin/113296?ref=mordauk">WordPress Announcements plugin</a>, and <a href="http://twitter.com/pippinspages">follow me on Twitter</a> to stay informed about the update coming any day now.</p><h3>Update</h3><p>Recently, I also found that you can use the action hooks like this:</p><div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'new_to_publish_{custom_post_type_name}'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'function_to_perform'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'draft_to_publish_{custom_post_type_name}'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'function_to_perform'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pending_to_publish_{custom_post_type_name}'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'function_to_perform'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>The combination of these three hooks will allow you to run a task only the first time the custom post type is published, and not every time it is updated as well.</p><h4 class='related-posts-header'>Related Posts</h4><ul class="related-posts-list"><li class="related-post"><a href="http://pippinspages.com/wordpress/email-notifications-for-wordpress-announcements/">Email Notifications for WordPress Announcements</a> <span class="related-post-date timestamp">Wed 06 Oct 2010</span></li><li class="related-post"><a href="http://pippinspages.com/wordpress/premium-wordpress-announcements-plugin/">Premium WordPress Announcements Plugin</a> <span class="related-post-date timestamp">Sat 17 Jul 2010</span></li><li class="related-post"><a href="http://pippinspages.com/wordpress/better-related-posts-widget/">Better Related Posts Widget</a> <span class="related-post-date timestamp">Sat 06 Aug 2011</span></li></ul>]]></content:encoded> <wfw:commentRss>http://pippinspages.com/tutorials/publish-action-hook-for-custom-post-types/feed/</wfw:commentRss> <slash:comments>12</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: basic
Database Caching 135/244 queries in 0.354 seconds using disk: basic
Object Caching 1260/1490 objects using disk: basic

Served from: www.pippinspages.com @ 2012-02-05 08:08:54 -->
