官术网_书友最值得收藏!

Creating the navigation bar

For the navigation bar, we can use the <nav> tag to wrap it up and make it responsive and ready with some tricks. Bootstrap helps us with the navigation component that we can integrate with a little help from jQuery.

In the header.phtml file, the navigation block looks as follows:

<!-- Navigation -->
<nav class="navbar navbar-default navbar-main" role="navigation">
<div class="container">
<div class="row">
<div class="navbar-header">
<a class="navbar-brand visible-xs" href="#">
<?php echo $this->__('Categories') ?>
</a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-main-collapse">
<span class="sr-only"><?php echo $this->__('Toggle Navigation') ?></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse navbar-main-collapse">
<?php echo $this->getChildHtml('topMenu') ?>
 <?php echo $this->getChildHtml('topSearch') ?>
</div>
</div>
</div>
</nav>

The top menu bar

The topmenu.phtml file is the navigation file that you can copy from app/design/frontend/base/default/template/page/html/.

The final code of this file is as follows:

<?php $_menu = $this->getHtml('level-top') ?>
<?php if ($_menu): ?>
<ul class="nav navbar-nav">
<li><a href="<?php echo $this->getUrl('') ?>" title="<?php echo $this->getLogoAlt() ?>">Home</a></li>
<?php echo $_menu ?>
</ul>
<?php endif ?>

Unfortunately, the Bootstrap menu has some classes that we cannot add in this file. To solve this problem, we can add the Bootstrap classes with some jQuery scripts.

So open the jquery.scripts.js file that you created before and add the following code just after jQuery(document).ready(function() {:

jQuery('.navbar .parent').addClass('dropdown');
jQuery('.navbar a.level-top').addClass('dropdown-toggle');
jQuery('.navbar li.parent ul').addClass('dropdown-menu');
jQuery('.navbar li.level1 ul').wrap('<li class="dropdown-submenu" />');
jQuery('.navbar ul.nav li.level0.dropdown').hover(function() {
jQuery(this).find('.level0.dropdown-menu').stop(true, true).fadeIn();
}, function() {
jQuery(this).find('.level0.dropdown-menu').stop(true, true).fadeOut();
});

Now add the following CSS code to hide the submenu that will be displayed only on the mousehover event with the jQuery described before:

/* Navbar */
.navbar {
  border:0 none;
  border-radius:0;
  margin:0;
  border-bottom:3px solid #E7E7E7;
}
.navbar .navbar-form {
  padding-right:10px;
}
.navbar-nav {
}
.navbar-default .navbar-nav > li:hover > a {
 background:#fff;
 box-shadow:0 6px 12px rgba(0,0,0,0.176);
}
.navbar ul.level0,.navbar ul.level1 {
  display:none;
  text-align:left;
}
.navbar .dropdown-menu {
border:0;
}
.navbar ul.level1 {
 left:150px;
 top:0;
}
.navbar-nav > li {
display:inline-block;
}

Search

The search file form.mini.phtml is the one you can copy from app/design/frontend/base/default/template/catalogsearch/.

As usual, we will change the code with the Bootstrap class and the final code will be as follows:

<?php $catalogSearchHelper =  $this->helper('catalogsearch'); ?>
<form id="search_mini_form" class="navbar-form navbar-right" role="search" action="<?php echo $catalogSearchHelper->getResultUrl() ?>" method="get">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><div class="glyphicon glyphicon-search pull-left"></div></span>
<input id="search" type="text"  name="<?php echo $catalogSearchHelper->getQueryParamName() ?>" value="<?php echo $catalogSearchHelper->getEscapedQueryText() ?>" class="form-control" maxlength="<?php echo $catalogSearchHelper->getMaxQueryLength();?>" placeholder="<?php echo $this->__('Search...') ?>" />
<span class="input-group-btn">
<button type="submit" class="btn btn-default">Submit</button>
</span>
</div>
</div>
<div id="search_autocomplete" class="search-autocomplete"></div></form>
<script type="text/javascript">
//<![CDATA[
var searchForm = new Varien.searchForm('search_mini_form', 'search', '<?php echo $this->__('Search...') ?>');
searchForm.initAutocomplete('<?php echo $catalogSearchHelper->getSuggestUrl() ?>', 'search_autocomplete');//]]>
</script>

The header is now completed and we can now proceed to develop the footer.

主站蜘蛛池模板: 苍溪县| 蕉岭县| 珠海市| 西城区| 无棣县| 赣州市| 观塘区| 鹰潭市| 葵青区| 定西市| 梁山县| 若尔盖县| 海安县| 天等县| 乌拉特前旗| 司法| 濮阳市| 南城县| 重庆市| 新河县| 鹿泉市| 介休市| 鹤峰县| 白朗县| 田东县| 惠东县| 襄城县| 肥西县| 房山区| 台东县| 南昌县| 浦城县| 伊金霍洛旗| 崇礼县| 瑞丽市| 开封市| 唐海县| 桑植县| 东宁县| 红原县| 呼伦贝尔市|