<?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>Luke Carbis</title>
	<atom:link href="http://lukecarbis.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://lukecarbis.com/blog</link>
	<description>It's more complicated than 42.</description>
	<lastBuildDate>Sun, 13 May 2012 22:14:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Add a parent menu class to wp_nav_menu</title>
		<link>http://lukecarbis.com/blog/2012/04/add-a-parent-menu-class-to-wp_nav_menu/</link>
		<comments>http://lukecarbis.com/blog/2012/04/add-a-parent-menu-class-to-wp_nav_menu/#comments</comments>
		<pubDate>Thu, 05 Apr 2012 02:24:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://lukecarbis.com/blog/?p=755</guid>
		<description><![CDATA[Today I needed to define a class for menu items that have a submenu. The menu items were outputted by wp_nav_menu, and I didn't want to use any Javascript. I found a class filter for when items are being created, and so my first approach was to check if the page had sub pages, which [...]]]></description>
			<content:encoded><![CDATA[<p>Today I needed to define a class for menu items that have a submenu. The menu items were outputted by wp_nav_menu, and I didn't want to use any Javascript.</p>
<p>I found a class filter for when items are being created, and so my first approach was to check if the page had sub pages, which seemed to work at first. I soon realised, however, that just because a page has children, it doesn't mean that it has child menu items, and pages without children can still have child menu items!</p>
<p>So here's my solution. Throw it in your themes functions.php file, and your wp_nav_menu items will receive the class 'parent-menu-item' if they have sub menu items.</p>
<blockquote><p>
function parent_menu_css_class( $classes, $item, $args ) {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;$menu_items = wp_get_nav_menu_items( $args-&gt;menu );</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;if ( ! $menu_items &amp;&amp; $args-&gt;theme_location &amp;&amp; ( $locations = get_nav_menu_locations() ) &amp;&amp; isset( $locations[ $args-&gt;theme_location ] ) ) :<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$menu = wp_get_nav_menu_object( $locations[ $args-&gt;theme_location ] );<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$menu_items = wp_get_nav_menu_items( $menu-&gt;term_id );<br />
&nbsp;&nbsp;&nbsp;&nbsp;endif;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;foreach ( $menu_items as $menu_item ) :</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( $menu_item-&gt;menu_item_parent == $item-&gt;ID ) :<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$classes[] = 'parent-menu-item';<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;endif;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;endforeach;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;return $classes;<br />
}<br />
add_filter( 'nav_menu_css_class', 'parent_menu_css_class', 10, 3 );</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://lukecarbis.com/blog/2012/04/add-a-parent-menu-class-to-wp_nav_menu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Including a Google Font in your WordPress theme the right way</title>
		<link>http://lukecarbis.com/blog/2012/04/including-a-google-font-in-your-wordpress-theme-the-right-way/</link>
		<comments>http://lukecarbis.com/blog/2012/04/including-a-google-font-in-your-wordpress-theme-the-right-way/#comments</comments>
		<pubDate>Mon, 02 Apr 2012 03:42:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://lukecarbis.com/blog/?p=749</guid>
		<description><![CDATA[Here's the best way to include a Google Font in your WordPress theme. 1. Prepare your font for use on Google Web Fonts. After you've chosen the styles and character sets you would like to include, copy the 'href' attribute of the include code. I'm using the font 'Neuton' in this example. 2. In your theme's [...]]]></description>
			<content:encoded><![CDATA[<p>Here's the best way to include a Google Font in your WordPress theme.</p>
<p>1. Prepare your font for use on Google Web Fonts. After you've chosen the styles and character sets you would like to include, copy the 'href' attribute of the include code. I'm using the font '<em>Neuton</em>' in this example.</p>
<div id="attachment_750" class="wp-caption aligncenter" style="width: 489px"><a href="http://lukecarbis.com/blog/wp-content/uploads/2012/04/Screen-Shot-2012-04-02-at-1.38.19-PM.jpg"><img class="size-full wp-image-750" title="Google Fonts Code" src="http://lukecarbis.com/blog/wp-content/uploads/2012/04/Screen-Shot-2012-04-02-at-1.38.19-PM.jpg" alt="" width="479" height="200" /></a><p class="wp-caption-text">Copy this part!</p></div>
<p>2. In your theme's functions.php file, include the following code, substituting the red example font details for your own:</p>
<blockquote style="text-align:left;"><p>function enqueue_fonts() {<br />
 wp_register_style( '<span style="color: #ff0000;">neuton-font</span>', '<span style="color: #ff0000;">http://fonts.googleapis.com/css?family=Neuton:300,700,400,400italic,200</span>' );<br />
 wp_enqueue_style( '<span style="color: #ff0000;">neuton-font</span>' );<br />
}<br />
add_action( 'init', 'enqueue_fonts' );</p></blockquote>
<p>3. You're good to go - you can now use the font in your stylesheet, as per Google's instructions.</p>
]]></content:encoded>
			<wfw:commentRss>http://lukecarbis.com/blog/2012/04/including-a-google-font-in-your-wordpress-theme-the-right-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to order by post meta item without setting meta_key in WordPress</title>
		<link>http://lukecarbis.com/blog/2011/11/how-to-order-by-custom-meta-item-without-setting-meta_key-in-wordpress/</link>
		<comments>http://lukecarbis.com/blog/2011/11/how-to-order-by-custom-meta-item-without-setting-meta_key-in-wordpress/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 06:58:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://lukecarbis.com/blog/?p=727</guid>
		<description><![CDATA[Problem: I wanted wp_query to sort by a custom meta item, but I also wanted it to include results that don't have that meta item assigned to them! When I use the built in 'orderby =&#62; 'meta_value', it requires me to set 'meta_key' =&#62; 'something' - and that won't include results that don't have that [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong> I wanted wp_query to sort by a custom meta item, but I also wanted it to include results that don't have that meta item assigned to them! When I use the built in <em>'orderby =&gt; 'meta_value'</em>, it requires me to set <em>'meta_key' =&gt; 'something'</em> - and that won't include results that don't have that meta_key assigned.</p>
<p><strong>Solution:</strong> I found some query filters that let me edit the SQL of the query, after all my other arguments have been considered. This means I can use an <em>INNER JOIN</em> and a different <em>ORDER BY</em> value to achieve the result I'm after. Here's the poetry:</p>
<pre>&lt;?php
add_filter( 'posts_clauses', 'my_custom_order_function', 20, 1 );
function my_custom_order_function( $pieces ) {

    $pieces['join'] .= " INNER JOIN (SELECT meta_id, post_id, meta_key, meta_value FROM wp_postmeta ORDER BY CASE meta_key WHEN 'custom_meta' THEN 1 ELSE 2 END ASC, meta_value ASC) AS cm1 ON (wp_posts.ID = cm1.post_id)";

    $pieces['orderby'] = "CASE cm1.meta_key WHEN 'custom_meta' THEN 1 ELSE 2 END, cm1.meta_value ASC, wp_posts.post_title ASC";

    return $pieces;

}
?&gt;</pre>
<p>Okay, so basically what we're doing here as adding a second postmeta table (the first is already added so that wp_query can handle meta queries), but before it's joined, we order it using MySQL's CASE order. This puts the meta_key we're looking for at the top of the JOIN, so if it exists, it will be that meta_key that is linked to our results.</p>
<p>Once we have joined the table, we just need to order by the join - again we do this using CASE, to put the results in the right order - items with our meta_key go first, and everything else second. We also do a secondary ORDER so that the items with the right meta_key also get ordered by meta_value.</p>
<p>It's important that you only use this code in context - pasting it in as is will force it to apply to every single query that is run on each page - and you probably don't want that.</p>
<p>If anyone can suggest a better way of doing it, or if there's something I missed, please let me know in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://lukecarbis.com/blog/2011/11/how-to-order-by-custom-meta-item-without-setting-meta_key-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

