<?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>Mike Van WinkleAdd tag-like functionality to your pod inputs | Mike Van Winkle</title>
	<atom:link href="http://www.mikevanwinkle.com/tag/how-to/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mikevanwinkle.com</link>
	<description>Wordpress/PHP Developer</description>
	<lastBuildDate>Tue, 31 Jan 2012 00:02:30 +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 tag-like functionality to your pod inputs</title>
		<link>http://www.mikevanwinkle.com/wordpress/add-tag-like-functionality-to-your-pod-inputs/</link>
		<comments>http://www.mikevanwinkle.com/wordpress/add-tag-like-functionality-to-your-pod-inputs/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 16:02:30 +0000</pubDate>
		<dc:creator>Mike Van Winkle</dc:creator>
				<category><![CDATA[Pods]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[helpers]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[podscms]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress How To]]></category>

		<guid isPermaLink="false">http://www.mikevanwinkle.com/?p=911</guid>
		<description><![CDATA[This pseudo-tutorial guides you through setting up a nifty helper for your WordPress pods. The helper emulates the native WordPress tag entry but applies it to whatever content type you specify. ]]></description>
			<content:encoded><![CDATA[<p><strong>Yet another update:</strong> The code below expects the name of your pick field to correspond to the name of the related pod type ( i.e. a pickfield name &#8220;genre&#8221; should relate to a pod called &#8220;genre&#8221; , as opposed to &#8220;file_type&#8221;).</p>
<p><strong><em>Warning: </em> My code highlighter is gimping up the code a little. If you plan to copy/paste, please <a href="http://www.mikevanwinkle.com/wp-content/uploads/2011/04/pods-tag-input.txt">download the text file</a> instead of copying straight from the webpag.</strong> </p>
<p><a href="http://mikevanwinkle.com/sandbox/wp/wp-admin/admin.php?page=pods-manage-books">Try the DEMO</a><br />
(login using guest/guest).</p>
<p><strong>Update: </strong>The demo was down yesterday because I was playing with some code. Sorry about that.</p>
<p><strong>Update 2: </strong><br />
Also note that if this input helper isn&#8217;t working on your site make sure that you&#8217;ve enqueued the &#8220;suggest&#8221; script which ships automatically with WordPress. Do this by adding the following line of code to your functions.php file:</p>
<pre class="brush:php">
if (!wp_script_is('suggest', 'queue') &#038;&#038; !wp_script_is('suggest', 'to_do') &#038;&#038; !wp_script_is('suggest', 'done'))  {
        wp_enqueue_script('suggest');
}
</pre>
<p>So this isn&#8217;t really a helper so I&#8217;m not going to add it to the PodsCMS helper gallery. However, I think it&#8217;s a useful bit of code for pods developers.</p>
<p>The problem: You prefer using pods for developing content that needs lots of relationships managed seamlessly. Post types and tags just won&#8217;t cut it. But man, you miss that slick tag UI that WordPress has where you just start typing, hit enter and POW the tag is added. Pods doesn&#8217;t have anything like this natively.</p>
<p>The solution:</p>
<p>First create a new input helper and paste in the following code:</p>
<pre class="brush:php">
<script>
jQuery.noConflict();
jQuery(document).ready(function() {
jQuery('#delete-tag').live('click', function(e) {
	e.preventDefault();
	jQuery(this).parent('span').remove();
});

jQuery('#<?php echo $css_id; ?>').find('input').suggest(ajaxurl+'?action=pods_suggest&#038;datatype=<?php echo $field['name']; ?>'); 

jQuery('#tag-input').click(function(e) {
	e.preventDefault();
	var new_tag = jQuery('#<?php echo $css_id; ?>').find('input').attr('value');
	var datatype = '<?php echo $field['name']; ?>';
	jQuery(this).next('div').append('<span><a href="" id="delete-tag" class="ntdelbutton">x</a> &nbsp; '+new_tag+'
<div class="option active" value="'+new_tag+'" style="display:none;"></div>

</span>');
	jQuery('#<?php echo $css_id; ?>').find('input').attr('value','');
});

jQuery('#<?php echo $css_id; ?>').find('input').keydown(function(event) {
	if (event.keyCode == '13') {
	var new_tag = jQuery('#<?php echo $css_id; ?>').find('input').attr('value');
	jQuery('#<?php echo $name; ?>-output').append('<span><a href="" id="delete-tag" class="ntdelbutton">x</a> &nbsp; '+new_tag+'
<div class="option active" value="'+new_tag+'" style="display:none;"></div>

</span>');
	jQuery('#<?php echo $css_id; ?>').find('input').attr('value','');
	}
});

});
</script>
<div class="<?php echo $css_classes; ?>" id="<?php echo $css_id; ?>" style="height:auto;background:transparent;border:none;">
<input name="<?php echo $name; ?>[]" type="text" class="" id="<?php echo $css_id; ?>" value=""  /><a href="#" id="tag-input" title="Add tag" class="button">
Add</a>
<div id="<?php echo $name; ?>-output" class="tagchecklist <?php echo $name; ?>list">
<?php foreach($value as $val): ?>
<?php if($val['active']): ?>
<span>
<a href="" id="delete-tag" class="ntdelbutton">x</a> &nbsp; <?php echo $val['name']; ?>
<div class="option active" value="<?php echo $val['name']; ?>" style="display:none;"><?php echo $val['name']; ?></div>

</span>
<?php endif; ?>
<?php endforeach; ?>
</div>
</div>
</pre>
<p>This helper creates an input field and calls up some jQuery magic to make it auto-complete. But in order for this magic to work you need to add a function to your functions.php (or a plugin file if that&#8217;s the case) and hook it to the wp_ajax_{$action} hook. For more about this hook check <a href="http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/">Gary Cao&#8217;s article</a>. </p>
<pre class="brush:php">
add_action('wp_ajax_pods_suggest','ajax_pod_search');
function ajax_pod_search() {
	if(isset($_GET['q'])) {
		$str = $_GET['q'];
		if(strlen($str) < 2) { die; }
			$pod = $_GET['datatype'];
			global $wpdb;
			$query = $wpdb->prepare("SELECT name FROM {$wpdb->prefix}pod_tbl_{$pod} WHERE name LIKE '%s'", '%'.like_escape($str).'%');
			$results = $wpdb->get_col($query);
			echo join( $results, "\n" );
		}
	die;
}
</pre>
<p>Now simply deploy the input_helper on your chosen <a href="http://podscms.org/codex/pick_column">multi-pick field pod</a>. </p>
<p>But wait! It&#8217;s not saving your pod items. That&#8217;s because PodsCMS expects to receive a list of comma-separated pod ids to register the relationship. But our jQuery is outputting the name instead. </p>
<p>So we now need to add a pre-save helper to manage migrating tag names to ids.</p>
<pre class="brush:php">
<?php
$field = 'genre';
if(isset($columns[$field]['value']) &#038;&#038; $columns[$field]['value'] != ''):
$names = explode(',',$columns[$field]['value']);
$names = (empty($names)) ? $columns[$field]['value'] : $names;
if(is_array($names)) {
$vals = array();
foreach($names as $name):
	$pid = pod_check($field, $name, 'name');
	if(!$pid)
	{
		$new_tag = new PodAPI();
		$pid = $new_tag->save_pod_item(array('datatype'=>$field, 'columns' => array('name'=>$name)));
	} else {
		$pid = (is_array($pid)) ? $pid[0] : $pid;
	}
	$vals[] = $pid;
endforeach;
} else {
	$pid = pod_check($field, $name, 'name');
	if(!$pid)
	{
	  $new_tag = new PodAPI();
	  $pid = $new_tag->save_pod_item(array('datatype'=>$field, 'columns' => array('name'=>$name)));
	} else {
		$pid = (is_array($pid)) ? $pid[0] : $pid;
	}
	$vals = $pid;
}
$val_str = implode(',',$vals);
$columns[$field]['value'] = $val_str;
endif;
?>
</pre>
<p>Note that we have to tell the helper the field to which we want it to apply. We do this by setting the $field variable. If you are going to use the input helper on multiple fields, you&#8217;ll want to create a pre-save helper for each field. This helper will iterate over the submitted pod <em>names</em>, check to see if that pod exists already and getting its <em>id</em>. If the pod name does not already exist, the helper will create it.</p>
<p>Note that this helper makes use of a function called &#8220;pod_check&#8221;. You will need to add this function to your functions.php file as well. </p>
<pre class="brush:php">
function pod_check($datatype, $value='', $field='id') {
    global $wpdb;
    $datatype = pods_sanitize($datatype);
    $field = pods_sanitize($field);
    $return = $wpdb->get_col($wpdb->prepare("SELECT `id` FROM `{$wpdb->prefix}pod_tbl_{$datatype}` WHERE `$field` = ".('id'==$field?"%d":"%s"),array($value)));
    if (true == $return &#038;&#038; 0 < $return) {
    	return $return;
    } else {
    	return false;
    }
}
</pre>
<p>This function actually does the work of looking up the pod <em>id</em>.</p>
<p>And that's it. You can make any pod into a "tag" using this approach. But keep in mind that if you are using this field to relate a pods with required fields, you will need to modify the pre-save helper to add those required fields. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikevanwinkle.com/wordpress/add-tag-like-functionality-to-your-pod-inputs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Meta Tag Titles and Descriptions for Your WordPress site.</title>
		<link>http://www.mikevanwinkle.com/wordpress/meta-tag-titles-and-descriptions-for-your-wordpress-site/</link>
		<comments>http://www.mikevanwinkle.com/wordpress/meta-tag-titles-and-descriptions-for-your-wordpress-site/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 13:46:27 +0000</pubDate>
		<dc:creator>Mike Van Winkle</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[meta tags]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress How To]]></category>

		<guid isPermaLink="false">http://www.mikevanwinkle.com/?p=364</guid>
		<description><![CDATA[There are many good plugins out there the help you easily add meta tags to your site. All-in-one-SEO is probably the most popular of all the options. But there several reason why you may want to manually add this code to your template. For one, you may be a template designer and want your templates to come [...]]]></description>
			<content:encoded><![CDATA[<p>There are many good plugins out there the help you easily add meta tags to your site. All-in-one-SEO is probably the most popular of all the options. But there several reason why you may want to manually add this code to your template.</p>
<p>For one, you may be a template designer and want your templates to come pre-installed with this SEO friend feature.</p>
<p>Second, you may be having issues with Facebook link sharing not working. WordPress plugins use the wp_head() hook to access your template. But you have no control over the order. If you are using more than a dozen plugins your meta tags can get buried under tons of other code. This can prevent some bots from finding them. Indeed on several of my site Facebook&#8217;s bot was not finding them.</p>
<p>Third, it is just always good to do things without plugins if possible. Call it Occum&#8217;s Razor of web site building, the less code you use, the better.</p>
<p>Luck for us, it is extremely simple to add code for meta tags and descriptions without knowing much about wordpress or PHP.</p>
<p>Open the header.php file in your theme and paste in the following code:</p>
<pre>
<div id="_mcePaste">&lt;?php if(is_singular()) { ?&gt;</div>
<div id="_mcePaste">&lt;?php</div>
<div id="_mcePaste">global $post;</div>
<div id="_mcePaste">?&gt;</div>
<div id="_mcePaste">&lt;?php $recent = new WP_query('p='.$post-&gt;ID);</div>
<div id="_mcePaste">while($recent-&gt;have_posts()) : $recent-&gt;the_post(); ?&gt;</div>
<div id="_mcePaste">&lt;meta name="title" content="&lt;?php the_title(); ?&gt;"&gt;</div>
<div id="_mcePaste">&lt;meta name="description" content="&lt;?php the_content_rss('', TRUE, '', 50); ?&gt;"&gt;</div>
<div id="_mcePaste">&lt;?php endwhile; ?&gt;</div>
<div id="_mcePaste">&lt;?php } else { ?&gt;</div>
<div id="_mcePaste">&lt;meta name="title" content="&lt;?php bloginfo('title'); ?&gt;"&gt;</div>
<div id="_mcePaste">&lt;meta name="description" content="&lt;?php bloginfo('description'); ?&gt;"&gt;</div>
<div id="_mcePaste">&lt;?php } ?&gt;</div>
</pre>
<p>So what&#8217;s going on here? First, we&#8217;re checking to see if the post is a single post using the WordPress Conditional tag &lt;?php if(is_singular()); ?&gt;<em> </em>because we&#8217;ll to pull the title and the description of the individual post for our meta tags. But to do this, we need to get some information about the post, which is why we use the call <code><em>global $post</em></code>. This will give us information about the current post. Particularly it allows us access to <code>$post-&gt;ID</code> to query information about the post using <code>WP_query</code>.</p>
<p>The query we us looks like this:</p>
<pre><code>$recent = new WP_query('p='.$post-&gt;ID); </code></pre>
<p>Once we have the query we put it into the standard wordpress loop:</p>
<pre><code>while($recent-&gt;have_posts()) : $recent-&gt;the_post();</code></pre>
<p>Then we use the standard WordPress tag &lt;?php the_title(); ?&gt; to pull in the META TITLE and &lt;? the_content_rss() ?&gt; to get the description. Notice, we are not using &lt;?php the_excerpt(); ?&gt;. This is because this WordPress tag prints the excerpt with a &#8220;read more&#8221; link in it. This will seriously screw up your theme. Using <a title="The Content RSS" href="http://codex.wordpress.org/Function_Reference/the_content_rss">&lt;?php the_content_rss(); ?&gt;</a> allows us to specify how many words of the content to pull in. But the second parameter has to be set to TRUE to avoid pulling in a &#8220;read more&#8221; link.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikevanwinkle.com/wordpress/meta-tag-titles-and-descriptions-for-your-wordpress-site/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SEO Link Building: Quality First</title>
		<link>http://www.mikevanwinkle.com/marketing/seo/seo-link-building-quality-first/</link>
		<comments>http://www.mikevanwinkle.com/marketing/seo/seo-link-building-quality-first/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 15:07:09 +0000</pubDate>
		<dc:creator>Mike Van Winkle</dc:creator>
				<category><![CDATA[SEO]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[SEOmoz.org]]></category>
		<category><![CDATA[videos]]></category>

		<guid isPermaLink="false">http://www.mikevanwinkle.com/?p=305</guid>
		<description><![CDATA[There&#8217;s always been a bit of tension between quantity and quality in link building campaigns. Do I build a widget that can get me thousand of links with minimal effort? Or do I focus on getting big links for a few dozen sources? Here&#8217;s a video from SEOMOZ.org on the growing importance of link quality. [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s always been a bit of tension between quantity and quality in link building campaigns. Do I build a widget that can get me thousand of links with minimal effort? Or do I focus on getting big links for a few dozen sources? Here&#8217;s a video from <a title="SEO Moz" href="http://www.seomoz.org">SEOMOZ.org</a> on the growing importance of link quality.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="293" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=6858200&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="293" src="http://vimeo.com/moogaloop.swf?clip_id=6858200&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><a href="http://vimeo.com/6858200">SEOmoz Whiteboard Friday &#8211; Link Quality vs. Quantity</a> from <a href="http://vimeo.com/user409469">Scott Willoughby</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mikevanwinkle.com/marketing/seo/seo-link-building-quality-first/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Object Caching 430/444 objects using apc

Served from: www.mikevanwinkle.com @ 2012-02-04 19:22:15 -->
