<?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>NemoPS &#187; blocktopmenu</title>
	<atom:link href="http://nemops.com/tag/blocktopmenu/feed/" rel="self" type="application/rss+xml" />
	<link>http://nemops.com</link>
	<description>Prestashop Tutorials, Modules and More!</description>
	<lastBuildDate>Wed, 05 Dec 2018 13:25:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.35</generator>
	<item>
		<title>Removing links from the top level in the PrestaShop top Menu</title>
		<link>http://nemops.com/prestashop-top-menu-removing-links/</link>
		<comments>http://nemops.com/prestashop-top-menu-removing-links/#comments</comments>
		<pubDate>Tue, 24 Nov 2015 10:35:40 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Tips n Tricks]]></category>
		<category><![CDATA[blocktopmenu]]></category>
		<category><![CDATA[category]]></category>
		<category><![CDATA[prestashop]]></category>
		<category><![CDATA[top menu]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=2608</guid>
		<description><![CDATA[<p>PrestaShop&#8217;s Top Menu usually lets you click on the first level categories, as well as their children in the mega-dropdown. In this quick tip, we will disable the top level links and let them be triggers for the menu only. Overriding the Top Horizontal Menu Module To make our modification scalable and have it preserve [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-top-menu-removing-links/">Removing links from the top level in the PrestaShop top Menu</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>PrestaShop&#8217;s Top Menu usually lets you click on the first level categories, as well as their children in the mega-dropdown. In this quick tip, we will disable the top level links and let them be triggers for the menu only.</p>
<p><span id="more-2608"></span></p>
<h2>Overriding the Top Horizontal Menu Module</h2>
<p>To make our modification scalable and have it preserve in future upgrades, of not only PrestaShop, but the module itself, we will create an override of it. Please notice overrides are only available for version 1.6.0.11 and newer. If you are using an older PrestaShop version, you will have to amend the core files directly.</p>
<p>Create a new folder named <strong>blocktopmenu</strong> inside <em>override/modules</em>. Within it, create a new file and name it <strong>blocktopmenu.php</strong>. Open it up in your favorite code editor and add some generic override code inside php tags:</p>
<pre class="brush: php; title: ; notranslate">

class BlockTopMenuOverride extends BlockTopMenu
{

}
</pre>
<p>We want to override a method named <strong>generateCategoriesMenu</strong>. It&#8217;s a protected function so we can easily extend it. Make sure you copy and paste the original one from your module here, as mine might differ even slightly:</p>
<pre class="brush: php; title: ; notranslate">

	protected function generateCategoriesMenu($categories, $is_children = 0)
	{
		$html = '';

		foreach ($categories as $key =&gt; $category)
		{
			if ($category['level_depth'] &gt; 1)
			{
				$cat = new Category($category['id_category']);
				$link = Tools::HtmlEntitiesUTF8($cat-&gt;getLink());
			}
			else
				$link = $this-&gt;context-&gt;link-&gt;getPageLink('index');

			$html .= '&lt;li'.(($this-&gt;page_name == 'category'
				&amp;&amp; (int)Tools::getValue('id_category') == (int)$category['id_category']) ? ' class=&quot;sfHoverForce&quot;' : '').'&gt;';
			$html .= '&lt;a href=&quot;'.$link.'&quot; title=&quot;'.$category['name'].'&quot;&gt;'.$category['name'].'&lt;/a&gt;';

			if ($category['level_depth'] &lt; 4 &amp;&amp; isset($category['children']) &amp;&amp; !empty($category['children']))
			{
				$html .= '&lt;ul&gt;';
				$html .= $this-&gt;generateCategoriesMenu($category['children'], 1);

				if ((int)$category['level_depth'] &gt; 1 &amp;&amp; !$is_children)
				{
					$files = scandir(_PS_CAT_IMG_DIR_);

					if (count($files) &gt; 0)
					{
						$html .= '&lt;li class=&quot;category-thumbnail&quot;&gt;';

						foreach ($files as $file)
							if (preg_match('/^'.$category['id_category'].'-([0-9])?_thumb.jpg/i', $file) === 1)
								$html .= '&lt;div&gt;&lt;img src=&quot;'.$this-&gt;context-&gt;link-&gt;getMediaLink(_THEME_CAT_DIR_.$file)
								.'&quot; alt=&quot;'.Tools::SafeOutput($category['name']).'&quot; title=&quot;'
								.Tools::SafeOutput($category['name']).'&quot; class=&quot;imgm&quot; /&gt;&lt;/div&gt;';

						$html .= '&lt;/li&gt;';
					}
				}

				$html .= '&lt;/ul&gt;';
			}

			$html .= '&lt;/li&gt;';
		}

		return $html;
	}
</pre>
<p>We are interested in the following line:</p>
<pre class="brush: php; title: ; notranslate">
			$html .= '&lt;a href=&quot;'.$link.'&quot; title=&quot;'.$category['name'].'&quot;&gt;'.$category['name'].'&lt;/a&gt;';
</pre>
<p>Which is the one responsible for displaying the link to each category. However, if we were to remove the anchor as it is, it would get rid of <strong>all</strong> the links, and we want to keep the ones inside mega menus. We need to add a condition that first checks we are dealing with our top level. How can we do it?<br />
The most logical way would be to check the &#8220;level_depth&#8221; property of the current category. This <em>might</em> work, in case your top menu categories all belong to the same depth level.</p>
<p>However, we can use another, more reliable variable: <strong>$is_children</strong>. It&#8217;s passed to each iteration of the loop used to generate the category tree, and checks whether we are in the top level or not, so it&#8217;s ideal for our purpose. Knowing that, we can replace the previous line with some logic:</p>
<pre class="brush: php; title: ; notranslate">
if ($is_children == 0)
	$html .= '&lt;a&gt;'.$category['name'].'&lt;/a&gt;';
else
	$html .= '&lt;a href=&quot;'.$link.'&quot; title=&quot;'.$category['name'].'&quot;&gt;'.$category['name'].'&lt;/a&gt;';
</pre>
<p>Please notice it needs an anchor wrapper in any case, to retain its style. Save the override, then reach the <em>cache</em> folder and get rid of <strong>class_index.php</strong> so that the override takes place. <strong>Depending on your configuration, you might as well need to go to Advanced Parameters, Performance, and clear cache.</strong></p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-top-menu-removing-links/">Removing links from the top level in the PrestaShop top Menu</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/prestashop-top-menu-removing-links/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Enable Ajax and Instant search for the Prestashop Top Menu</title>
		<link>http://nemops.com/ajax-instant-search-prestashop-top-menu/</link>
		<comments>http://nemops.com/ajax-instant-search-prestashop-top-menu/#comments</comments>
		<pubDate>Wed, 19 Feb 2014 09:23:40 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[blocktopmenu]]></category>
		<category><![CDATA[prestashop]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=1880</guid>
		<description><![CDATA[<p>Ajax and instant search are a quick way to display results to your customers without having them wait for a page reload. Let&#8217;s see how to implement this in the Prestashop Top Menu search bar! Watch The Screencast &#160;</p>
<p>The post <a rel="nofollow" href="http://nemops.com/ajax-instant-search-prestashop-top-menu/">Enable Ajax and Instant search for the Prestashop Top Menu</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Ajax and instant search are a quick way to display results to your customers without having them wait for a page reload. Let&#8217;s see how to implement this in the Prestashop Top Menu search bar!</p>
<p><span id="more-1880"></span></p>
<h2>Watch The Screencast</h2>

	<div class="video-embed">
		<iframe width="640" height="360" src="http://www.youtube.com/embed/nwawlF1HiQY#038;feature=youtu.be" frameborder="0" allowfullscreen></iframe><p><a href="https://www.youtube.com/user/NemoPostScriptum/videos" rel="nofollow" title="Subscribe Post Scriptum's Youtube Channel">Subscribe Post Scriptum's Youtube Channel</a></p>	</div>
<p>The post <a rel="nofollow" href="http://nemops.com/ajax-instant-search-prestashop-top-menu/">Enable Ajax and Instant search for the Prestashop Top Menu</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/ajax-instant-search-prestashop-top-menu/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Prestashop top menu: add &#8216;active&#8217; state for current page</title>
		<link>http://nemops.com/prestashop-top-menu-current-state/</link>
		<comments>http://nemops.com/prestashop-top-menu-current-state/#comments</comments>
		<pubDate>Mon, 28 Jan 2013 14:00:40 +0000</pubDate>
		<dc:creator><![CDATA[Nemo]]></dc:creator>
				<category><![CDATA[Theming]]></category>
		<category><![CDATA[blocktopmenu]]></category>
		<category><![CDATA[prestashop]]></category>
		<category><![CDATA[top menu]]></category>

		<guid isPermaLink="false">http://nemops.com/?p=966</guid>
		<description><![CDATA[<p>It seems that many people are having trouble in targeting the &#8220;current&#8221; state for a link in the Prestashop top menu. In this quick tip, we will see how to do it, and we&#8217;ll also go beyond the basics and show the topmost parent for current subcategories and other pages. Version used: Prestashop 1.5.3 (compatible [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-top-menu-current-state/">Prestashop top menu: add &#8216;active&#8217; state for current page</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>It seems that many people are having trouble in targeting the &#8220;current&#8221; state for a link in the Prestashop top menu. In this quick tip, we will see how to do it, and we&#8217;ll also go beyond the basics and show the topmost parent for current subcategories and other pages.</p>
<p><span id="more-966"></span></p>
<ul>
<li>Version used: <strong>Prestashop 1.5.3 (compatible with all 1.5 top menus)</strong></li>
</ul>
<h2>Step 1 &#8211; Inspecting the Prestashop top menu and preparing files</h2>
<p>First of all, let&#8217;s have a look at the top menu, and see what can be done to target the &#8220;current&#8221; class. Click on any top level category of your shop, and fire up your favorite debugging toolbar (I&#8217;ll use Chrome Developer Tools in this example)</p>
<div id="attachment_980" style="width: 690px" class="wp-caption aligncenter"><a href="http://nemops.com/wp-content/uploads/2013/01/img1.jpg"><img src="http://nemops.com/wp-content/uploads/2013/01/img1-680x239.jpg" alt="Prestashop top menu with active state - current link inspection" width="680" height="239" class="size-large wp-image-980" /></a><p class="wp-caption-text">The current element has the sfHoverForce class assigned</p></div>
<p>As you can see, when in a category, that very same link&#8217;s parent is given the class <strong>sfHoverForce</strong>. Easy enough to target, isn&#8217;t it?</p>
<p>Now, it&#8217;s bad practice to directly edit core files, therefore we will use an override for the stylesheet, and another one for the javascript. Go to the modules folder, then <strong>blocktopmenu</strong>, and copy the <em>css/</em> folder. Reach your theme folder, open <em>css/</em>, and, if not already there, create a new subfolder called <em>modules</em>. Inside it, create a new folder named <em>blocktopmenu</em>, and finally paste the css folder inside this.</p>
<p>You might also want to copy the entire <em>img/</em> folder of the module inside this one (not css/, the parent), so that you can see images.</p>
<p>For the javascript, go back to the original module&#8217;s folder, open <em>js/</em> and copy <strong>superfish-modified.js</strong>. Again, in your theme&#8217;s folder, open <em>js/</em>, then <em>modules/</em> (which should already be there, if not, create it), and create another folder named, useless to say, <em>blocktopmenu</em>. Inside it, create one last folder called <em>js</em>, and paste the superfish file inside it.</p>
<p>If you did it correctly, you should have the following structure:</p>
<ul>
<li>theme_name/css/modules/blocktopmenu/css/superfish-modified.css</li>
<li>theme_name/css/modules/blocktopmenu/img/all image files&#8230;</li>
<li>theme_name/js/modules/blocktopmenu/js/superfish-modified.js</li>
</ul>
<p>If not, or if all this sounded like vodoo magic to you, have a look at the official <a href="http://doc.prestashop.com/display/PS15/Overriding+default+behaviors#Overridingdefaultbehaviors-Overridingamodule'sbehavior" target="_blank" title="Prestashop - Overriding modules behavior"> Prestashop documentation about overriding a module&#8217;s default behavior</a>.</p>
<div class="separator"></div>
<h2>Step 2 &#8211; Adding the current menu item&#8217;s style</h2>
<p>Now that our files are properly setup, open up <strong>superfish-modified.css</strong> (not the original one, but the one you copied over in the theme&#8217;s folder). Please note that I&#8217;m using the default Prestashop template for this example. Let&#8217;s target our &#8220;current&#8221; class first. At the end of the file, add the following style:</p>
<pre class="brush:css">
.sf-menu > li.sfHoverForce > a{
	background-color: white;
	color: #000 !important;
	text-shadow: none;
}
</pre>
<p><strong>Explanation:</strong> Just some ordinary css. I&#8217;m targeting the anchor tag(a) which is direct descendant of the shHoverForce-classed li, which is itself direct child of the topmost menu element. I&#8217;m doing this, and with descendant selectors, since I don&#8217;t want any other sub-link to have the &#8220;current&#8221; state&#8217;s white background, but only the top level ones. Of course, if you do want it, feel free to use a regular selector. Also note that I&#8217;m just using some ordinary styles for demonstration purposes; feel free to change the values as you like.</p>
<p>If we now reload the page, we will see something like this</p>
<div id="attachment_988" style="width: 458px" class="wp-caption aligncenter"><a href="http://nemops.com/wp-content/uploads/2013/01/accessories_with_current.png"><img src="http://nemops.com/wp-content/uploads/2013/01/accessories_with_current.png" alt="Prestashop top menu with active state - current page added" width="448" height="137" class="size-full wp-image-988" /></a><p class="wp-caption-text">The link to current page now shows as &#8220;active&#8221;</p></div>
<p><strong>NOTE:</strong> the top menu block is bugged in 1.5.3.1 (with chrome at least). Therefore, when you&#8217;re in a category, not all subcategories will show up in the menu. Fixing it is beyond the scope of this tutorial, thus I will not cover it.</p>
<p>You will see we are currently targeting the actual category we are in. But what if we are in a subcategory, or other pages? Let&#8217;s look at the other pages first, and the class they have been assigned.</p>
<p>I created 2 more links in the top menu, one linked to a product (the Belkin Folio) and another one linked to a CMS page. By inspecting those links when in the respective pages, I can see they&#8217;ve been assigned the <strong>sfHover</strong> class. Weird. This is not consistent, Prestashop Team! &#8230; But let&#8217;s put complaints aside and deal with it. We could target that class, of course, but that&#8217;s also the name of the class assigned to an element when hovering on it with the mouse, and this is bad if we want to have two separate styles. We&#8217;ll need to add some javascript to handle this.</p>
<div class="separator"></div>
<h2>Step 3 &#8211; Target other pages and subcategories</h2>
<p>First, open up <strong>superfish-modified.js</strong> (again, the override!). Locate the jQuery wrapper at about line 122 (Prestashop 1.5.3.1). You will see something like this:</p>
<pre class="brush:javascript">
jQuery(function(){
	jQuery('ul.sf-menu').superfish();
});	
</pre>
<p>Inside that wrapper, after the superfish() function call, add the following</p>
<pre class="brush:javascript">
	$('.sfHover').addClass('sfHoverForce'); // will only target current links, since it's fired upod page load
</pre>
<p>And this way, as written in the comment, we are appending our sfHoverForce class to the elements that already have .sfHover when the page loads (therefore, we don&#8217;t affect any further hover state). refresh the product or CMS page, and you&#8217;ll see it&#8217;s now properly targeted. Cool, but we&#8217;re not done yet. I added a subcategory to Accessories, and I can see Accessories itself is not set as &#8220;current&#8221; if I&#8217;m in that subcategory. We have to fix this, and it will be a bit more complex. In the very same javascript file, add the following code after that last one we just wrote:</p>
<pre class="brush:javascript">
	function recursiveCheck(element)
	{
		if (!element.length)
			return;
		var the_ul = element.parent(); // unordered list parent
		if (the_ul.hasClass('sf-menu'))
			element.addClass('sfHoverForce'); //means it is another list item, add the class
		else recursiveCheck(the_ul.parent());
	}
	recursiveCheck($('.sfHoverForce'));
</pre>
<p><strong>Explanation:</strong> wait! Don&#8217;t run away! First we create a &#8220;recursive function&#8221;. This function grabs the current sub-link with the class sfHoverState as the only argument. First, it checks that there currently is at least one element with that class applied. If not, it breaks, otherwise we might end up in an infinite loop. It then creates a variable for its direct parent (the unordered list). If this parent <strong>is</strong> the top most menu element (with the class sf-menu) we add the sfHoverForce class to the current list item. If not, we call the very same function again, and this time the argument we pass is <strong>the parent ul&#8217;s parent</strong>, therefore another list item, one level higher than our first one. We go on with this until we reach the top level, and add the current state to our top level link. This will work with the many sub-category levels you can imagine. Lastly, we call the function by targeting the only link that currently has the sfHoverForce class as the page loads (alas, our subcategory in this case).</p>
<div id="attachment_991" style="width: 646px" class="wp-caption aligncenter"><a href="http://nemops.com/wp-content/uploads/2013/01/final_result.png"><img src="http://nemops.com/wp-content/uploads/2013/01/final_result.png" alt="Prestashop top menu with active state - finished result" width="636" height="306" class="size-full wp-image-991" /></a><p class="wp-caption-text">Finished result. This will work with all pages &#038; subcategories</p></div>
<p>Reload the page in any subcategory, and you should have the links as you want!</p>
<p>The post <a rel="nofollow" href="http://nemops.com/prestashop-top-menu-current-state/">Prestashop top menu: add &#8216;active&#8217; state for current page</a> appeared first on <a rel="nofollow" href="http://nemops.com">NemoPS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nemops.com/prestashop-top-menu-current-state/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
	</channel>
</rss>
