Magento 1.7.2 - How to include CMS pages in topmenu? - php

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>

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!!

Make Menu Template Dynamic

I'm currently developing a website and decided to have the menus to be written in a separate file.
Currently I have a php page holding the menu list called menu.php
<?php
$menu='<div class="headMenu">
<ul>
<li><span>Home</span></li>
<li><span>Transaction</span></li>
<li><span>Schedule</span></li>
<li><span>Book</span></li>
</ul>
</div>';
echo $menu;
?>
Whenever you enter the Transaction Page, the distinct code for that page is
<li class="active"><span>Transaction</span></li>
and same as the other pages,
I'm thinking this can be done in jquery using its .addClass() method, but I have no idea of passing variables from one page to the separate page holding the menu written in php
Why not to do a function in menu.php that returns a string containing menu with "activated" page?
If I understand your question correctly, this would be helpfull:
<?php
function renderMenu($site){
$menu='<div class="headMenu">
<ul>
<li '. ($site=="index.php"?'class="active"':'') .'><span>Home</span></li>
//etc...
</ul>
</div>';
return $menu;
?>
And then in your main script:
echo renderMenu(__FILE__);

how to link a page url to wordpress

I'm new to WordPress, I just converted my HTML to WP Theme, but now I'm facing a problem, I couldn't get to work the linking of pages.
The structure of my theme:
index.php
header.php
sidebar.php
footer.php
services.php <- other page in the site
Here's the sample code from index.php:
<div id="menu">
<ul>
<li><a class="current" href="#">Home</a></li>
<li>Services</li>
<li>Free Quote</li>
<li>Customers</li>
<li>About Us</li>
<li>Contact us</li>
</ul>
</div>
But whenever I try to go to services, it's giving internal server error. I don't know why it's happening.
There are two ways in wordpress for linking Pages
For Content Based pages only:
You need to create a page from wp-admin(Admin panel) and can specify the slug of the page
E.g:
<li>Services</li>
^This is called Slug
This page will always run from page.php.
For HTML Changes Pages:
You need to create a page from wp-admin(Admin panel) and create a file containing
page-slug.php, here slug will change according to the name of page.E.g:
Services page will become page-services.php, in this you can insert your own html.
This will run from page-services rather than page.php
Choose as per your requirement.
Try using:
<a href="<?php echo bloginfo("template_url")?>/services.php">
I think in this case you are just not echoing out the value of that function. Also, however you might want this instead:
<a href="<?php echo home_url() ?>/services">
The template_url goes to your theme's folder, not to your website's homepage. I assume the latter is what you're really going for.
try <php echo site_url()."/sevices.php"; ?>

Magento Redirect URL?

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.

Categories