Add magento CMS pages to navigation bar - magento

I am new to Magento and completely lost. I have a problem in assigning CMS pages to navigation bar.
Say from manage categories I am creating a sub category contact us & want to show a cms page named contact us in the frontend when clicking on that contact us menu. What do I have to do for that? And after clicking on the menu it should go to a page like mysite.com/contact-us.html. It is going there but it's showing there are no products matching the selection.

You can use this code to get all cms pages dynamically in navigation
Place this code in header file below topcontainer
<?php $collection = Mage::getModel('cms/page')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId());?>
<?php $collection->getSelect()
->where('is_active = 1'); ?>
<ul id="nav">
<?php foreach ($collection as $page): ?>
<?php $PageData = $page->getData(); ?>
<?php// print_r($PageData);?>
<?php if($PageData['identifier']!='no-route' && $PageData['identifier']!='enable-cookies' && $PageData['identifier']!='home2') { ?>
<li>
<span><?php echo $PageData['title'] ?></span>
</li>
<?php } ?>
<?php endforeach; ?>
</ul>
Note change this part of code "/magento/index.php/" according to your domain

Create a category
Create your cms page
Create an URL rewrite that redirects your category to your cms page.
Thus, you will have a link in the menu and that link would redirect
to your CMS page.
Example:
Category:
Name: About Us
URL Key: about-us
ID: 4
CMS page:
Name: About Us
URL Key: about-us
URL Rewrite:
Type: Custom
ID Path: about-us
Request path: catalog/category/view/id/4
Target path: about-us/
Redirect: Permanent

Related

Magento: Switch From Grid view To List View, Without Changing URL

I was wondering if you could guide me how to allow the user to select either list or grid view, without changing the URL of the catalog/category page.
I.e., the page is either www.example.com/category?mode=grid OR www.example.com/category?mode=list but I want to make it just www.example.com/category and show the grid view by default, with the list view being displayed without changing the URL.
I hope you can help
There is no tutorial I guess..you have to do your own code ..And its not a big deal .. Open your list.phtml file in app/design/frontend/default/YOURTHEME/template/catalog/product/
Here you can see, they separate two view mode like this,
<div class="category-products">
<?php echo $this->getToolbarHtml() ?>
<?php // List mode ?>
<?php if($this->getMode()!='grid'): ?>
<?php $_iterator = 0; ?>
<ol class="products-list" id="products-list">
<?php foreach ($_productCollection as $_product): ?>
..bla.. bla ...
And Grid mode:
<?php else: ?>
<?php // Grid Mode ?>
Here they check the mode like this
<?php if($this->getMode()!='grid'): ?>
Just remove this condition, so that you can load both views, so now just add new css class or id to separate both modes, and manage them by Js like onclik event or something like that ...

show welcome message only on index.php [CI]

I make custom welcome message in codeigniter script, but i want show only on index.php
I have
<div class="welcome">
<?php echo getConfigSetting('config_welcome') ?>
</div>
This message show in header,on all page. I want show only on homepage (index.php)
I already tried this code but give me a blank page
<?php if( $this->uri->segment(1) == 'home' || $this->uri->segment(1) = '' ): ?>
Affordable Business Websites Done Fast…
"Just find a website you like and we will customize it to your business needs, easy as 123!"
Start Search
</div>
</div>
Any sugestion?
Thank you
you could try to use the CI helper URL and grab the first segment of the url to check whta page we are on.
example:
<?php if( $this->uri->segment(1) == 'home' || $this->uri->segment(1) = '' ): ?>
<div class="welcome">
<?php echo getConfigSetting('config_welcome') ?>
</div>
<?php endIf; ?>
of course you would want to change the "home" to the name of your homepage name you see in the url, or the default controller/method name.
You will also want to make sure you autoload the url_helper in the config/autoload.

Magento Active Filters on Search Page

I want to implement active filters on my magento ecommerce site.
I have been successful in implementing it, but the issue is, the code works on only category pages and not search page
Here's the code that I'm using
<?php /*Create filter dependencies*/
$_activeFilters[] = array();
$_filters = Mage::getSingleton(‘Mage_Catalog_Block_Layer_State’)->getActiveFilters();
foreach ($_filters as $_filter):?>
<?php echo $this->stripTags($_filter->getLabel()) ?><a href=”<?php echo $_filter- >getRemoveUrl() ?>” title=”<?php echo $this->__(‘Remove This Item’) ?>”><?php echo $this->__(‘Remove This Item’) ?></a>
<?php endforeach; ?>
I'm using this code in toolbar.phtml. Any clue as in why its not working on search page. Any Solutions would be of great help.
Thanks,
Sushil
You can use this code for fetching filters on either category list page or search results page
<?php
if(Mage::registry('current_category')) {
$_filters = Mage::getSingleton('catalog/layer')->getState()->getFilters();
} else {
$_filters = Mage::getSingleton('catalogsearch/layer')->getState()->getFilters();
}
?>
I have used this code in toolbar.phtml, to show removable filters below the toolbar, like flipkart does.
The problem is with this line:
$_filters = Mage::getSingleton(‘Mage_Catalog_Block_Layer_State’)->getActiveFilters();
This gets a singleton which only contains the necessary data when on a category page.
See this question for more details: Magento - How to add Layered Navigation to Advanced Search?

Show Product on Search Page - Magento 1.7

Currently I have a snippet of code that will forward a user to the product page if they search for a term and only 1 product is associated with that keyword.
<?php if($this->getResultCount() == 1): ?>
<?php $prodId = $this->_productCollection->getAllIds() ?>
<?php $singleProduct = Mage::getModel('catalog/product')->load($prodId) ?>
<?php header('Location: ' . $singleProduct->getProductUrl()) ?>
<?php exit; ?>
<?php elseif($this->getResultCount()): ?>
However, what I want to do now is actually serve up the product and all its details on the results page itself if its the only one with that tag/search term INSTEAD of redirecting to the product page. Im pretty new to php so please bear with me.
Block template is bad place for this. Good place - controller.
Maybe you need rewrite controller for this functionality.
For example/app/code/core/Mage/CatalogSearch/controllers/ResultController.php
In controller your code looks like:
$this->getResponse()->setRedirect($_product->getProductUrl());

Magento Page Title - include SKU as well as product name

How do I include the SKU as well as the product name in the page title (when looking at the product details page)?
Cheers!
In app/design/frontend/default/{your theme Folder}/template/page/html/head.phtml you could try
<?php if ($_product = Mage::registry('current_product')) { ?>
<title><?php echo $_product->getName() . ' ' . $_product->getSku(); ?></title>
<?php }else{ ?>
<title><?php echo $this->getTitle() ?></title>
<?php } ?>
You could also do this using an observer for catalog_controller_product_view see Magento Change Product Page Titles to Include Attributes
If you have a collection already loaded (ie. on product view page)
$_product->getSku();
If for some reason you need to call this from a different template higher up in the chain that isn't already loading the product/collection, you can drop this one:
$_product = Mage::registry('current_product');
$_product->getSku();
look at your design template in catalog/product/view.phtml file you should be able to simply do $_product->getData('sku');

Resources