<?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>digitalnature &#187; code</title>
	<atom:link href="https://digitalnature.eu/blog/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>https://digitalnature.eu</link>
	<description>Rise Above the Ordinary</description>
	<lastBuildDate>Fri, 11 Sep 2015 15:02:35 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
		<item>
		<title>Featured images (thumbnails) in menus</title>
		<link>https://digitalnature.eu/blog/2011/10/27/featured-images-thumbnails-in-menus/</link>
		<comments>https://digitalnature.eu/blog/2011/10/27/featured-images-thumbnails-in-menus/#comments</comments>
		<pubDate>Thu, 27 Oct 2011 12:27:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Useless Stuff]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[menus]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://digitalnature.eu/?p=2215</guid>
		<description><![CDATA[The following code will let you use featured images as thumbnails in your custom menus. Paste this in your child theme functions.php file, or theme settings &#62; Advanced &#62; User-defined code:

atom()-&#62;setContextArgs('primary_menu', array('walker' =&#62; new ThumbMenuWalker()));

class ThumbMenuWalker  [...]]]></description>
			<content:encoded><![CDATA[<p>The following code will let you use featured images as thumbnails in your custom menus. Paste this in your child theme functions.php file, or theme settings &gt; Advanced &gt; User-defined code:</p>
<pre class="php">
atom()-&gt;setContextArgs('primary_menu', array('walker' =&gt; new ThumbMenuWalker()));

class ThumbMenuWalker extends AtomWalkerNavMenu{

  // register the thumbnail size, 64 pixel square, cropped
  function __construct(){
    add_image_size('nav-thumb', 64, 64, true);
  }

  // override start_el
  function start_el(&amp;$output, $item, $depth, $args) {

    $classes = empty($item-&gt;classes) ? array() : (array)$item-&gt;classes;

    $classes = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args));
    $classes = $classes ? ' class=&quot;'.esc_attr($classes).'&quot;' : '';

    $output .= &quot;\n&lt;li{$classes}&gt;&quot;;

    $attributes  = !empty($item-&gt;attr_title) ? ' title=&quot;'.esc_attr($item-&gt;attr_title).'&quot;' : '';
    $attributes .= !empty($item-&gt;target) ? ' target=&quot;'.esc_attr($item-&gt;target).'&quot;' : '';
    $attributes .= !empty($item-&gt;xfn) ? ' rel=&quot;'.esc_attr($item-&gt;xfn).'&quot;' : '';
    $attributes .= !empty($item-&gt;url) ? ' href=&quot;'.esc_attr($item-&gt;url).'&quot;' : '';

    $excerpt = $thumb = '';

    // 2nd level+
    if($depth &gt; 0){
      $post = new AtomObjectPost($item-&gt;object_id);

      // thumbnail image
      if(post_type_supports($item-&gt;object, 'thumbnail'))
        $thumb = $post-&gt;getThumbnail('nav-thumb');

    if($thumb)
      $attributes .= ' class=&quot;clear-block&quot;';

      // short description from the content, 100 is the max. character count
      $excerpt = $post-&gt;getContent(100, array(
        'cutoff'       =&gt; 'sentence',  // cut off just after the sentence ends
        'allowed_tags' =&gt; array(),     // no html
        'more'         =&gt; false,       // no 'more' text / link
      ));

      if($excerpt)
        $excerpt = &quot;&lt;small&gt;{$excerpt}&lt;/small&gt;&quot;;
      
      atom()-&gt;resetCurrentPost();
    }

    $content = $args-&gt;link_before.$thumb.'&lt;span class=&quot;tt&quot;&gt;'.apply_filters('the_title', $item-&gt;title, $item-&gt;ID).$excerpt.'&lt;/span&gt;'.$args-&gt;link_after;
    $output .= apply_filters('walker_nav_menu_start_el', &quot;{$args-&gt;before}&lt;a{$attributes}&gt;{$content}&lt;/a&gt;{$args-&gt;after}&quot;, $item, $depth, $args);
  }

}</pre>
<p>The CSS:</p>
<pre class="css">.nav img, .nav .no-img{
  float:left;
  margin-right: 5px;
} 

.nav .tt{
  overflow:hidden;
  display:block;
  font-weight:bold;  
}  

.nav small{
  font-size:11px;  
  display:block;
  margin-top: 5px;
}</pre>
<p>The result should be something like this:<br />
<img class="alignnone size-full wp-image-2216" title="Menu thumbanils" src="http://digitalnature.eu/wp-content/uploads/2011/10/thumb-menu.png" alt="Menu thumbanils" width="560" height="307" /></p>
]]></content:encoded>
			<wfw:commentRss>https://digitalnature.eu/blog/2011/10/27/featured-images-thumbnails-in-menus/feed/</wfw:commentRss>
		<slash:comments>98</slash:comments>
		</item>
	</channel>
</rss>
