<?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>mummey.org &#187; wordpress</title>
	<atom:link href="http://www.mummey.org/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mummey.org</link>
	<description>Personal Website of Adrian Mummey</description>
	<lastBuildDate>Tue, 27 Oct 2009 03:11:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Finding a Category Ancestor / Descendant for WP Templates</title>
		<link>http://www.mummey.org/2009/03/finding-a-category-ancestor-descendant-wp-templates/</link>
		<comments>http://www.mummey.org/2009/03/finding-a-category-ancestor-descendant-wp-templates/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 06:01:02 +0000</pubDate>
		<dc:creator>Adrian Mummey</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[ancestor]]></category>
		<category><![CDATA[category]]></category>
		<category><![CDATA[children]]></category>
		<category><![CDATA[descendent]]></category>

		<guid isPermaLink="false">http://www.mummey.org/?p=365</guid>
		<description><![CDATA[Recently I had a problem where I needed to find out if a specific category was a descendant of another category, or if one category was a ancestor of another. The latest website I am working on has a top level category called &#8220;Trips we do&#8221; and below that are many sub-categories and sub-sub categories [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I had a problem where I needed to find out if a specific category was a descendant of another category, or if one category was a ancestor of another. The latest website I am working on has a top level category called &#8220;Trips we do&#8221; and below that are many sub-categories and sub-sub categories etc. I wanted to use the same template on all of the categories that were descended from the &#8220;Trips we do&#8221;.<br />
Wordpress already has a function that returns the parent categories <a href="http://codex.wordpress.org/Template_Tags/get_category_parents">get_category_parents</a> but this returns a string more suited for breadcrumbs. I needed a yes or no answer that my category in question was in fact descended from some other arbitrary category. Here is the function I produced:</p>
<pre><code class="php">function is_ancestor_cat($ancestor, $descendant){
  $ancestor = (string) $ancestor;
  $desc_id = (string) $descendant;
  $child_cats = get_term_children( (string) $ancestor, &#39;category&#39;);
  if($ancestor == $descendant){
    return true;
  }
  else if(!count($child_cats)){
    return false;
  }
  else{
    $is_child = false;
    foreach($child_cats as $cat_id){
      if($cat_id == $desc_id){
        $is_child = true;
        break;
      }
      else{
        $is_child = $is_child || is_ancestor_cat($cat_id, $descendant);
      }
    }
    return $is_child;
  }
}</code></pre>
<p>What this code does is that is grabs all the children for the <em>ancestor</em> category then checks them against the <em>descendant</em> category, it will keep recursing until it hits the leaf nodes and returns a boolean value.<br />
Here it is in action in my template file <em>category.php</em>:</p>
<pre><code class="php">//Check if we are in a category
if(is_category()){
  $ancestor_cat_id = 43;
  //Lets get the current category we are in
  $cur_cat_id = get_cat_id( single_cat_title(&quot;&quot;,false) );
  $is_ancestor = false;
  //Check if we are in the ancestor category
  $is_ancestor = is_ancestor_cat($ancestor_cat_id, $cur_cat_id);

  //If it is an ancestor, use a specific template
  if($is_ancestor){
   include(TEMPLATEPATH.&#39;/category-43.php&#39;);
  }
  //Use the default template
  else{
   include(TEMPLATEPATH.&#39;/category-default.php&#39;);
  }

}</code></pre>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.mummey.org%2F2009%2F03%2Ffinding-a-category-ancestor-descendant-wp-templates%2F&amp;linkname=Finding%20a%20Category%20Ancestor%20%2F%20Descendant%20for%20WP%20Templates"><img src="http://www.mummey.org/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.mummey.org/2009/03/finding-a-category-ancestor-descendant-wp-templates/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Styling Wordpress Dynamic Sidebar &#8211; dynamic_sidebar_params Filter</title>
		<link>http://www.mummey.org/2009/02/styling-wordpress-dynamic-sidebar-dynamic_sidebar_params-filter/</link>
		<comments>http://www.mummey.org/2009/02/styling-wordpress-dynamic-sidebar-dynamic_sidebar_params-filter/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 04:38:23 +0000</pubDate>
		<dc:creator>Adrian Mummey</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[dynamic sidebar]]></category>
		<category><![CDATA[dynamic_sidebar_params]]></category>
		<category><![CDATA[filter]]></category>

		<guid isPermaLink="false">http://www.mummey.org/?p=166</guid>
		<description><![CDATA[I have been working a lot lately on customizing my personal homepage theme. One thing I have not been happy about has been the right sidebar. The widget heading were just html text and didn&#8217;t have the rendered look that I wanted. I decided to reformat the sidebar and use images for the headings rather [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working a lot lately on customizing my personal homepage theme. One thing I have not been happy about has been the right sidebar. The widget heading were just html text and didn&#8217;t have the rendered look that I wanted. I decided to reformat the sidebar and use images for the headings rather than just text. I had done some custom sidebars before but I wasn&#8217;t sure how to style each widget independently. The problem is that WP gives a generic class to each sidebar widget and you are only able to style all of them to look the same.<br />
The first place I looked for a function to do this was in my template&#8217;s function.php file and I noticed this code:</p>
<pre><code class="php">
if ( function_exists(&#39;register_sidebar&#39;) )
    register_sidebar(array(
        &#39;before_widget&#39; =&gt; &#39;&lt;div class=&quot;sidebar-box&quot;&gt;&#39;,
    &#39;after_widget&#39; =&gt; &#39;&lt;/div&gt;&lt;/div&gt;&#39;,
 &#39;before_title&#39; =&gt; &#39;&lt;h2&gt;&lt;span&gt;&#39;,
        &#39;after_title&#39; =&gt; &#39;&lt;/span&gt;&lt;/h2&gt;&lt;div class=&quot;sidebar-box-inside&quot;&gt;&#39;,
    ));
</code></pre>
<p>This isn&#8217;t exacly what I wanted as it will apply this to all of my widgets. So after a little more snooping around the web I noticed a WP filter that does what I want. The fitler is called <em>dynamic_sidebar_params</em> and it is called like this:</p>
<pre><code class="php">
add_filter('dynamic_sidebar_params', 'my_function_callback');
</code></pre>
<p>Where <em>my_function_callback</em> is the name of your function. In my case I called it like this, in <em>functions.php</em>:</p>
<pre><code class="php">
add_filter('dynamic_sidebar_params', 'sidebar_styling');
</code></pre>
<p>Next I had to figure out a way to style each element uniquely. I decided that the widget name would be a good identifier. Luckily this filter will pass you a field called widget_id, which has a sanitized version of the name which can be used for your CSS identifier. Here is what the params variable looks like:</p>
<pre><code class="php">
Array
(
    [name] =&gt; Sidebar 1
    [id] =&gt; sidebar-1
    [before_widget] =&gt; &lt;div class=&quot;sidebar-box&quot;&gt;

    [after_widget] =&gt; &lt;/div&gt;&lt;/div&gt;
    [before_title] =&gt; &lt;h2&gt;&lt;span&gt;
    [after_title] =&gt; &lt;/span&gt;&lt;/h2&gt;&lt;div class=&quot;sidebar-box-inside&quot;&gt;
    [widget_id] =&gt; recent-posts
    [widget_name] =&gt; Recent Posts
)
</code></pre>
<p>Now that we have that ID, it is a simple function to write:</p>
<pre><code class="php">function sidebar_styling($params){
  $params[0][&#39;before_title&#39;] = &#39;&lt;h2 id=&quot;sidebar-&#39;.@$params[0][&#39;widget_id&#39;].&#39;&quot;&gt;&lt;span&gt;&#39;;
  return $params;
}</code></pre>
<p>Now WP will output the unique id for each heading and we can just style it appropriately. I used a big sprite to save resources:<br />
<div id="attachment_169" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.mummey.org/wp-content/uploads/2009/02/dynamic-sidebar.png"><img src="http://www.mummey.org/wp-content/uploads/2009/02/dynamic-sidebar-150x150.png" alt="Dynamic Sidebar" title="dynamic-sidebar" width="150" height="150" class="size-thumbnail wp-image-169" /></a><p class="wp-caption-text">Dynamic Sidebar</p></div><br />
And then styled it like this, I am hiding the span so that we don&#8217;t see the text, but it will degrade nicely if you haven&#8217;t yet styled one of your widget classes.</p>
<pre><code class="css">
#sidebar-recent-posts span{display: none;}
#sidebar-recent-posts{
  background: transparent url(images/sidebar-titles/dynamic-sidebar.png) 0 0 no-repeat !important;
}
#sidebar-twitter-tools span{display: none;}
#sidebar-twitter-tools{
  background: transparent url(images/sidebar-titles/dynamic-sidebar.png) 0 -41px no-repeat !important;
}
#sidebar-categories span{display: none;}
#sidebar-categories{
  background: transparent url(images/sidebar-titles/dynamic-sidebar.png) 0 -82px no-repeat !important;
}
#sidebar-archives span{display: none;}
#sidebar-archives{
  background: transparent url(images/sidebar-titles/dynamic-sidebar.png) 0 -123px no-repeat !important;
}
#sidebar-links span{display: none;}
#sidebar-links{

  background: transparent url(images/sidebar-titles/dynamic-sidebar.png) 0 -164px no-repeat !important;
}
</code></pre>
<p>That is all there is, you can see the results on the page you are reading.<br />
I found these articles/sites helpful:</p>
<ul>
<li> <a href=" http://wordpress.org/support/topic/206194" title="Dynamic Widget Classes for use in CSS" alt="Dynamic Widget Classes for use in CSS">Dynamic Widget Classes for use in CSS</a></li>
</ul>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.mummey.org%2F2009%2F02%2Fstyling-wordpress-dynamic-sidebar-dynamic_sidebar_params-filter%2F&amp;linkname=Styling%20Wordpress%20Dynamic%20Sidebar%20%26%238211%3B%20dynamic_sidebar_params%20Filter"><img src="http://www.mummey.org/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.mummey.org/2009/02/styling-wordpress-dynamic-sidebar-dynamic_sidebar_params-filter/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Wordpress &#8211; Use NextGen Gallery Code Inside an Excerpt</title>
		<link>http://www.mummey.org/2009/02/wordpress-use-nextgen-gallery-code-inside-an-excerpt/</link>
		<comments>http://www.mummey.org/2009/02/wordpress-use-nextgen-gallery-code-inside-an-excerpt/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 06:48:19 +0000</pubDate>
		<dc:creator>Adrian Mummey</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[excerpt]]></category>
		<category><![CDATA[gallery]]></category>
		<category><![CDATA[nextgen]]></category>

		<guid isPermaLink="false">http://www.mummey.org/?p=147</guid>
		<description><![CDATA[One problem with the ways that Wordpress handles excerpt is that it always strips the HTML out. This is fine for most casual bloggers but when you are really trying to customize something for a client, it simply doesn&#8217;t cut it. What we wanted to do was use some of the NextGen Gallery markdown code [...]]]></description>
			<content:encoded><![CDATA[<p>One problem with the ways that Wordpress handles excerpt is that it always strips the HTML out. This is fine for most casual bloggers but when you are really trying to customize something for a client, it simply doesn&#8217;t cut it. What we wanted to do was use some of the NextGen Gallery markdown code in the &#8220;Excerpt&#8221; box of the post and have Wordpress render this in the category archive.</p>
<p>After some initial research I discovered that this markdown code is called &#8220;shortcode&#8221; in WP terminology. They have a whole <a href="http://codex.wordpress.org/Shortcode_API">Shortcode API</a>. Now it was just a matter of finding the correct functions to get the shortcode to render.</p>
<p>I wanted to create a special template for the category, essentially a <strong>photo blog</strong>, so that it would look different from the other categories. This is pretty straightforward, just create a new file called category-<em>id</em>.php, where <em>id</em> is the id number of your category. In my case it was category-40.php. The next step was to copy all the code from category.php and paste it into category-40.php.</p>
<p>When displaying the post&#8217;s excerpt, Wordpress uses a function called <strong>the_excerpt()</strong>. Here it is in the default sandbox template:</p>
<pre><code class="php">
the_excerpt(''.__('Read More &lt;span class="meta-nav"&gt;&amp;raquo;&lt;/span&gt;', 'sandbox').'') ;
</code></pre>
<p>The problem with the_excerpt is that is echoes the excerpt directly to the screen. In order to return the excerpt value as a string we need to use <strong>get_the_excerpt()</strong>. Next after checking the shortcode API, I discovered a function that will run all the shortcodes on a given string and return the output as a string, <strong>do_shortcode()</strong>.</p>
<p>So all we need to do now is combine these two functions, and move it into the template:</p>
<pre><code>
echo do_shortcode(get_the_excerpt());
</code></pre>
<p>And there it is!</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.mummey.org%2F2009%2F02%2Fwordpress-use-nextgen-gallery-code-inside-an-excerpt%2F&amp;linkname=Wordpress%20%26%238211%3B%20Use%20NextGen%20Gallery%20Code%20Inside%20an%20Excerpt"><img src="http://www.mummey.org/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.mummey.org/2009/02/wordpress-use-nextgen-gallery-code-inside-an-excerpt/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
