<?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/"
	xmlns:media="http://search.yahoo.com/mrss/">

<channel>
	<title>Jon Bishop &#187; WordPress Hack</title>
	<atom:link href="http://www.jonbishop.com/tag/wordpress-hack/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jonbishop.com</link>
	<description>Social Media, WordPress and Web Development</description>
	<lastBuildDate>Tue, 10 Jan 2012 21:55:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Creating A Video Section On Your WordPress Blog</title>
		<link>http://www.jonbishop.com/2009/10/creating-a-video-section-on-your-wordpress-blog/</link>
		<comments>http://www.jonbishop.com/2009/10/creating-a-video-section-on-your-wordpress-blog/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 19:40:35 +0000</pubDate>
		<dc:creator>Jon Bishop</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Themes]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[WordPress Hack]]></category>

		<guid isPermaLink="false">http://www.jonbishop.com/?p=1490</guid>
		<description><![CDATA[Awhile back I decided to]]></description>
			<content:encoded><![CDATA[<p>Awhile back I decided to start posting videos on my blog. Once I had a few videos up I began to rethink my approach. Ultimately I wanted to prevent videos from showing up where normal posts are displayed and instead display my most recent video in the sidebar.<span id="more-1490"></span></p>
<p>To do this, I would need to:</p>
<ul>
<li>Suppress all video posts from being displayed with other posts</li>
<li>Create an archive of all video posts</li>
<li>Resize and place my most recent video in the sidebar</li>
</ul>
<p><strong>The first step</strong> was pretty easy. I just created a new category called &#8220;Video Post&#8221; and assigned it to all of my video posts. This would become a fairly intuitive list of videos people could access at their will.</p>
<p><strong>Next</strong> I wanted to remove all video posts from being displayed among other posts on the home page. However, I still wanted my videos to be displayed in RSS feeds as well as archives and search pages. To do this, I just modified the default WordPress query used to pull the most recent posts by placing the following code before &#8220;The Loop&#8221;.</p>
<div class="geshi no php">
<div class="head">//Hide a category from the home page</div>
<ol>
<li class="li1">
<div class="de1"><span class="kw3">global</span> <span class="re1">$wp_query</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">query_posts<span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">array_merge</span><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">array</span><span class="br0">&#40;</span><span class="st0">&#39;cat&#39;</span> <span class="sy0">=&amp;</span>gt<span class="sy0">;</span> <span class="nu0">-66</span><span class="br0">&#41;</span><span class="sy0">,</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re1">$wp_query</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>query</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p><strong>Be sure to change</strong> &#8216;-66&#8242; to the id of whatever category you are trying to hide. <a href="http://wordpress.org/support/topic/226313">How do I find the category IDs?</a></p>
<p>Also, if you are not sure where the WordPress Loop begins, it is usually located inside of index.php in your theme folder and starts with:</p>
<div class="geshi no php">
<div class="head">//Beginning of the WordPress Loop located in index.php of theme</div>
<ol>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span> have_posts<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="sy0">:</span> <span class="kw1">while</span> <span class="br0">&#40;</span> have_posts<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="sy0">:</span> the_post<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p><strong>The last step</strong> is to display my most recent video in the sidebar. To do this I decided my best course of action was to save the embed code of my videos into a custom field as well as within the content of the post. This would allow me to easily pull the embed code and I would still be able to add text along with my video within the content.</p>
<p style="text-align: center;"><img class="size-full wp-image-1502 aligncenter" title="Create custom field for embed code" src="http://www.jonbishop.com/wp-content/uploads/2009/10/video_embed.jpg" alt="Create custom field for embed code" width="470" height="100" /></p>
<p>In the example below I used the custom field &#8216;embed&#8217; in my posts. Just paste this code in your sidebar where you would like your video to be displayed.</p>
<div class="geshi no php">
<div class="head">//Display resized most recent video along with link to previous video</div>
<ol>
<li class="li1">
<div class="de1">ID<span class="sy0">,</span> <span class="re1">$key</span><span class="sy0">,</span> <span class="kw2">true</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re1">$custom_field</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">// Set values</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="re1">$width</span> <span class="sy0">=</span> <span class="st0">&#39;width=&quot;&#39;</span><span class="sy0">.</span><span class="re1">$width</span><span class="sy0">.</span><span class="st0">&#39;&quot;&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="re1">$height</span> <span class="sy0">=</span> <span class="st0">&#39;height=&quot;&#39;</span><span class="sy0">.</span><span class="re1">$height</span><span class="sy0">.</span><span class="st0">&#39;&quot;&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="re1">$custom_field</span> <span class="sy0">=</span> <span class="kw3">preg_replace</span><span class="br0">&#40;</span> <span class="st0">&#39;/width=&quot;[^&quot;]+&quot;/&#39;</span> <span class="sy0">,</span> <span class="re1">$width</span> <span class="sy0">,</span> <span class="re1">$custom_field</span> <span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="re1">$custom_field</span> <span class="sy0">=</span> <span class="kw3">preg_replace</span><span class="br0">&#40;</span> <span class="st0">&#39;/height=&quot;[^&quot;]+&quot;/&#39;</span> <span class="sy0">,</span> <span class="re1">$height</span> <span class="sy0">,</span> <span class="re1">$custom_field</span> <span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw3">echo</span> <span class="st0">&#39;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="st0"> &lt;li id=&quot;recent-videos&quot; class=&quot;widget widget_recent_videos&quot;&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="st0">&lt;h3&gt;Videos&lt;/h3&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="st0">&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;?<span class="sy0">&amp;</span>gt<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>ul<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="sy0">&lt;</span>li style<span class="sy0">=</span><span class="st0">&quot;text-align: center;&quot;</span><span class="sy0">&gt;&lt;</span>strong<span class="sy0">&gt;&lt;</span>a href<span class="sy0">=</span><span class="st0">&quot;&amp;lt;?=get_permalink(); ?&amp;gt;&quot;</span><span class="sy0">&gt;</span>ID<span class="br0">&#41;</span><span class="sy0">;</span> ?<span class="sy0">&amp;</span>gt<span class="sy0">;&lt;/</span>a<span class="sy0">&gt;&lt;/</span>strong<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;</span>ul<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="sy0">&lt;</span>li<span class="sy0">&gt;</span>Next Video<span class="sy0">:</span> <span class="sy0">&lt;</span>a href<span class="sy0">=</span><span class="st0">&quot;&amp;lt;?=get_permalink(); ?&amp;gt;&quot;</span><span class="sy0">&gt;</span>ID<span class="br0">&#41;</span><span class="sy0">;</span> ?<span class="sy0">&amp;</span>gt<span class="sy0">;&lt;/</span>a<span class="sy0">&gt;&lt;/</span>li<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span>ul<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span>li<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span>ul<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span>li<span class="sy0">&gt;</span></div>
</li>
</ol>
</div>
<p>You will notice I also included a link to my last video however you can remove this or replace it with a link to your video archive. This code should work with most video embed codes. Be sure to change the width and height so everything fits nicely into your sidebar.</p>
<p>And that&#8217;s it. Now all you need to do when adding a new video post is:</p>
<ol>
<li>Assign the post to your video category</li>
<li>Paste your embed code into the content and your &#8216;embed&#8217; custom field</li>
<li>And Publish Your Post!</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.jonbishop.com/2009/10/creating-a-video-section-on-your-wordpress-blog/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	<enclosure url="http://www.jonbishop.com/wp-content/uploads/2009/10/video_embed_wordpress.jpg" length="26007" type="image/jpg" /><media:content url="http://www.jonbishop.com/wp-content/uploads/2009/10/video_embed_wordpress.jpg" width="470" height="150" medium="image" type="image/jpeg" />	</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: enhanced (User agent is rejected)
Database Caching 10/20 queries in 2.263 seconds using disk: basic

Served from: jonbishop.com @ 2012-02-07 05:58:45 -->
