Magento Redirect URL? - php

Hellow friemds i develop a magento website and i created page and i want to linked that page into navigation menu bar
http://www.magentocommerce.com/knowledge-base/entry/adding-page-links-in-the-navigation-bar

Starting With Magento CE 1.7 there is an event that lets you add anything to the top menu.
The event is page_block_html_topmenu_gethtml_before. In the default theme, this is used to add categories in the menu. Check out the method Mage_Catalog_Model_Observer::addCatalogToTopmenuItems(). You can do the same.
If you are working on versions before 1.7 just edit the file app/design/frontend/{interface}/{theme}/template/catalog/navigation/top.phtml and add your link inside the ul element:
<ul id="nav">
<?php echo $_menu ?>
<li><?php echo $this->__('Text here')?></li>
</ul>
or like this
<ul id="nav">
<?php echo $_menu ?>
<li><?php echo $this->__('Text here')?></li>
</ul>
The approach for version 1.6 works in 1.7 also but it's not that clean.

Related

PHP dynamic navigation submenu

I have created a dynamic nav menu for a website. The menu loads to each page from a separate file, therefore i am using php required on all pages. I am trying to highlight the menu item when visitor is on each page and i cannot use JS or jQuery. All should be done in PHP, CSS and HTML only.
So far, i have the following function in the navigation file:
<?php
function setActive($name){
global $pageName;
if ($pageName == $name){
echo "class='active' ";
}
}
?>
And example of a menu:
<ul>
<li ><a <?php setActive ('v')?> href="v.php">Home</a></li>
<li>
cd
<ul class="hidden">
<li>a</li>
<li>b</li>
</ul>
</li>
</ul>
The function works for main menu, but i cannot get it work for submenu pages. I want the item cd to highlight when visitor lands on page a.php or b.php.
Any ideas how to solve it?
Thanks

How to add external link to top menu item in magento

I am using Magento 1.9.
My top menu contains categories as menu items.
I have managed to open static CMS page when clicked on menu item (i.e. category) by adding custom URL rewrite rule from admin panel.
How I can add menu item with external link to it so that page will get redirected to other website when clicked on menu item.
My Magento website is going to be under subdoamin and external link will be of main doamin.
Magento site will be hosted on http://domain.xyz.dom/ and I need to redirect to http://www.xyz.dom/abc when clicked on menu item.
The way you added cms page in "URL Rewrite Management" you can add external url too.
Create a category, in my case category ID is 3
Add a new URL Rewrite from URL rewrite management
Enter ID Path: category/3
Enter Request Path: catalog/category/view/id/3
Enter your external url in "Target Path"
There can be two ways of redirecting the way you are trying.
From Cateagory Url rewrite management which i guess you have tried so far.
Another way is little messy but it will work you just have to add a static link on the template file.
I mean go to the file
app/design/frontend/your_package/your_theme/template/page/html/topmenu.phtml
you will see some code like this
<?php $_menu = $this->getHtml('level-top') ?>
<?php if($_menu): ?>
<nav id="nav">
<ol class="nav-primary">
<?php echo $_menu ?>
</ol>
</nav>
<?php endif ?>
I have replaced this to add a home page link on the menu see below.
<?php $_menu = $this->getHtml('level-top') ?>
<?php $baseUrl = Mage::getBaseUrl();?>
<?php $currentUrl = Mage::helper('core/url')->getCurrentUrl();?>
<?php if($_menu): ?>
<nav id="nav">
<ol class="nav-primary">
<li class="level0 nav-1 <?php if($baseUrl==$currentUrl){echo 'active';}?>">Home</li>
<?php echo $_menu ?>
</ol>
</nav>
<?php endif ?>
In this way you can add your link.
Hope this helps. Happy Coding!!

Magento 1.7.2 - How to include CMS pages in topmenu?

I have created 2 CMS pages in magento 1.7.2
Lets say the cms page "About Us" which is the URL
http://localhost/magento/index.php/about-company/?___store=default
and the page "Customer Service" which is the URL http://localhost/magento/index.php/customer-service/?___store=default
In my HEADER.PHTML the line getChildHtml('topMenu') ?> shows the topmenu.
the problem is that the 'topMenu' contains only the categories created by Catalog->Manage Categories
What is the appropriate way to include the 2 cms pages ("About Us" and "Customer Service")
in the 'topMenu' ?
Thank you for your help !
Create a static block for cms pages from admin and write the below format code
<ul>
<li>About Company</li>
<li>Customer Service</li>
</ul>
Call this block in topmenu.phtml (/template/page/html/topmenu.phtml) page
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('cms_pages')->toHtml();?>
Add following code under your /template/page/html/topmenu.phtml
<li title="<?php echo $this->__('About Company') ?>"><?php echo $this->__('About Company') ?></li>

How to add a div class to Wordpress Auto Nav?

I have the following code to display all pages into a nav bar in Wordpress
<ul>
<?php wp_list_pages('title_li='); ?>
</ul>
Trying to figure out how to add a div class to each li?
You should be able to use link_before and link_after:
<ul>
<?php wp_list_pages('title_li=&link_before=<div class="myClass">&link_after=</div>'); ?>
</ul>
There's a section on styling the <li>s in the documentation.

Hide categories that have no products magento

I have many sites that use the same root category of the Main Site. Each product that is added is added to the site it was added to (wow.) and also the Main Site. However, I would like categories on a per site basis to only appear if there are products on that site.
If I have:
Category1
Category2
Category3
But Site1 only has products in Category1 and Category2, whereas Site2 and Site3 have products in Category2 and Category3; I only want Category1/2 to appear on Site1 and only Category2/3 to only appear on Site2 and Site3.
However, because all products in Site1/2/3 are also added to the Main Site; the Main Site would list Category1/2/3.
No products are added directly to the Main Site. It simply serves as a repository for the other sites.
Now, if there is no really easy way to enable this (as I'm sure), would it be as simple as writing my own theme that lists categories that only have products on the site that the template is being displayed on?
I am not a novice in the technologies that Magento uses; so writing custom code is no problem. I would, however, not like to edit it that much so that upgrading my code base would be easier in the future with later versions of Magento.
Thanks,
-nelson
Well, what you can do is, create your own helper with a collection (through a model), and then filter the collection based on product count.
Only a rough draft, but I've posted some code in another magento related question: Magento products by categories. You can see how and when it adds the products count, I'd filter again when this is done.
I don't think this is extremely "great" in terms of performance, so instead of using their model classes, you could write your own, extending it and adding default filters, or shortcutting directly to the database.
As long as you stay in your skin/template, there are no larger issues with updating.
this is a simple solution to hide categories that might help you .
The original contents of the top.phtml file should look like below.
<?php $_menu = $this->renderCategoriesMenuHtml(0,'level-top') ?>
<?php if($_menu): ?>
<div>
<ul id="nav">
<?php echo $_menu ?>
</ul>
</div>
<?php endif ?>
Replace the code above with this code below.
<?php $_menu = ''?>
<?php $excludeCat = array(); ?>
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php if($_category->getProductCount() <=0) {
$excludeCat[] = $_category->getId();
}
?>
<?php $_menu .= $this->drawItem($_category) ?>
<?php endforeach ?>
<?php if ($_menu): ?>
<div>
<ul id="nav">
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php if (!in_array($_category->getId(), $excludeCat)) : ?> <?php echo $this->drawItem($_category) ?>
<?php endif; ?>
<?php endforeach ?>
</ul>
</div>
<?php endif; ?>

Categories