I want to make the class active when user clicks on perticular link for navigation menu
I am new in php code igniter so how can make it dynamic way
suppose you have 4 pages and there page id's are 1,2,3,4 than you can do it like that
<li><a href="<?php echo base_url(); ?>home" class="<?php echo ($page_id==1?'active':'')?>" >Home</a><span>|</span></li>
<li><a href="<?php echo base_url(); ?>about" class="<?php echo ($page_id==2?'active':'')?>" >About Us</a><span>|</span></li>
<li><a href="<?php echo base_url(); ?>services" class="<?php echo ($page_id==3?'active':'')?>" >Services</a><span>|</span></li>
<li>Contact Us</li>
I hope it 'll help you!!
Related
I have created a new1.phtml file in catalog/product with following content
<?php
//getting new product collection
$product=Mage::getModel("catalog/product")->getCollection();
$filtered_prodduct=$product->addAttributeToSelect("*")
->setOrder("created_at","desc")
->addPriceData();
echo "<ul>
<li>";
$i=0;
$row=3;
foreach($filtered_prodduct as $prod){
$i++;
if($i>$row*3){
break;
}
?>
<div class="prod_box">
<div class="center_prod_box">
<div class="product_title">
<a href="<?php echo $prod->getProductUrl()?>">
<?php echo $prod->getName() ?>
</a>
</div>
<div class="product_img">
<a href="<?php echo $prod->getproductUrl()?>">
<img src="<?php echo $prod->getImageUrl()?>" alt="" border="0" height="100" width="100">
</a>
</div>
<div class="prod_price">
<span class="reduce"><?php echo $prod->getSpecialPrice()?></span>
<span class="price"><?php echo $prod->getPrice()?></span><br/>
</div>
</div>
<div class="prod_details_tab">
<?php if($prod->isSaleable()): ?>
<a href="<?php echo $this->getUrl()?>checkout/cart/add? product=<?php echo $prod->getId(); ?>&qty=1" class="prod_buy">
<?php echo $this->__('Add') ?>
</a>
<?php else: ?>
<p class="availability out-of-stock"><span>
<?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<a href="<?php echo $prod->getProductUrl()?>" class="prod_details">
Details
</a>
</div>
</div>
<?php }
?>
Every thing is ok ,but 'Add' button (means add to cart) is not working .It just opens checkout/cart.
i have added this phtml file in layout xml of home page. what is wrong in the code ?
You can do this my using below code ,which generated add to cart url.
Mage::helper('checkout/cart')->getAddUrl(($prod);
If product type is configurable and group or if product type is simple and it have customoption ,then it did not cart directly without selecting any options
The controller's action validates request therefore you should send formKey
public function addAction()
{
if (!$this->_validateFormKey()) {
$this->_goBack();
return;
}
...
{
Mage::helper('checkout/cart')->getAddUrl(($prod);
I want to make my topmenu link active when clicked on it.It contains Home, Specials(category name),About Us(cms page),FAQ(cms page) and Contact us.I want that when i clicked on any of the upper link,that link will be active.I used one class "active-1" for that.I want any condition to make the toplink active when clicked on it.
the code used in topmenu.phtml page whick make you easy to understand.
<style>
.nav-container ul.somelink li.active-1 a{ background:#fa9c04;}
</style>
<?php $_menu = $this->getHtml('level-top') ?>
<?php $page_route=Mage::app()->getRequest()->getRouteName(); ?>
<?php $pageID = Mage::getBlockSingleton('cms/page')->getPage()->getIdentifier();?>
<div class="nav-container">
<ul class="somelink">
<li <?php if($pageID=="home") echo 'class="active-1"';?> ><a href="
<?php echo Mage::getBaseUrl();?>">Home</a></li>
<li <?php if($pageID=="specials.html") echo 'class="active-1"';?>><a href="
<?php echo $this->getUrl('specials.html') ?>">Specials</a></li>
<li <?php if($pageID=="about-us") echo 'class="active-1"';?>><a href="
<?php echo $this->getUrl('about-us') ?>">About Us</a></li>
<li <?php if($pageID=="faq") echo 'class="active-1"';?>><a href="
<?php echo $this->getUrl('faq') ?>">FAQ</a></li>
<li <?php if($page_route=="contacts") echo 'class="active-1"';?>><a href="
<?php echo Mage::getBaseUrl();?>contacts">contact Us</a></li>
</ul>
</div>
the above code works but when i am clearing the cache,then the menu will be active,it is not active at that time i have to clear the cache again and again for making the menu active
I usually do it from css.
So have the menu like you have it, but add some classes to each item:
<?php $_menu = $this->getHtml('level-top') ?>
<div class="nav-container">
<ul class="somelink">
<li><a class="home-link" href="<?php echo $this->getUrl('') ?>">Home</a></li>
<li><a class="specials-link" href="<?php echo $this->getUrl('specials.html') ?>">Specials</a></li>
<li><a class="about-link" href="<?php echo $this->getUrl('about-us') ?>">About Us</a></li>
<li><a class="faq-link" href="<?php echo $this->getUrl('faq') ?>">FAQ</a></li>
<li><a class="contact-link" href="<?php echo $this->getUrl('contacts') ?>">Contact Us</a></li>
</ul>
</div>
Since every magento page has a different class on the <body> element you can use that.
Add the following to your css file. (replace color:red with the properties that highlight your menu item)
.cms-index-index .home-link { /* for homepage*/
color:red;
}
.cms-specials .specials-link { /*for specials page */
color:red
}
....
As a general rule, visit every page in your menu, get the specific class from the body and add a line like this to the css
.[body-class-here] .[link-to-be-selected-class-here] {
color:red
}
An alternative for the 1.7+ version would be to add the menu items directly in the top menu using the page_block_html_topmenu_gethtml_before event. When adding a menu item, the item supports an 'active' property, where you can put the code to make the link active.
See this for more info
Hi I think this will help's u, try this,
<?php $_menu = $this->getHtml('level-top') ?>
<?php $page_route=Mage::app()->getRequest()->getRouteName(); ?>
<?php $pageID = Mage::getBlockSingleton('cms/page')->getPage()->getIdentifier();?>
<div class="nav-container">
<ul class="somelink">
<li <?php if($pageID=="home") echo 'class="active"';?> ><a href="
<?php echo Mage::getBaseUrl();?>">Home</a></li>
<li <?php if($pageID=="specials.html") echo 'class="active"';?>><a href="
<?php echo $this->getUrl('specials.html') ?>">Specials</a></li>
<li <?php if($pageID=="about-us") echo 'class="active"';?>><a href="
<?php echo $this->getUrl('about-us') ?>">About Us</a></li>
<li <?php if($pageID=="faq") echo 'class="active"';?>><a href="
<?php echo $this->getUrl('faq') ?>">FAQ</a></li>
<li <?php if($page_route=="contacts") echo 'class="active"';?>><a href="
<?php echo Mage::getBaseUrl();?>contacts">contact Us</a></li>
</ul>
</div>
And add active class like this .nav-container ul li.active(color:red);
I'm redesigning a client's top-level category pages and I would like to future-proof the design by making it dynamic. To further clarify, I want it so whenever the client adds, edits or removes a category below the current level, it would reflect that on the frontend without the need of editing code.
Now, I have come across some blog posts on the topic and even a Stack forum post:
http://www.templatemonster.com/help/magento-listing-sub-categories-on-a-category-page.html
how to display thumbnail from category using getThumbnailUrl() in Magento
However, these are both handling it differently. The Stack post also lead me to:
http://www.douglasradburn.co.uk/getting-category-thumbnail-images-with-magento/
Which I found out I needed to add the functionality for pulling the Thumbnail Image (way to go Magento). BUT, this is what I need! The end goal here is to use the Thumbnail Image on the backend of the Category, NOT the Image. We're using the Image elsewhere, as intended. I also would like to be able to pull in the category description from the backend to the frontend for the purpose of adding some extra information such as links, a true description, etc.
If there anyone who can help me? I went through the above examples and links and still, the Thumbnail images were not pulling to the frontend and overall, I'm just getting some weird behaviour. Any tips would be appreciated as I research this further myself.
Thank you!
Please Try below code. I have implemented the same with this
<?php $category_path = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA)."catalog/category/"; ?>
<?php if (!Mage::registry('current_category')) return ?>
<?php $_categories = $this->getCurrentChildCategories() ?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php if($_count): ?>
<div class="static-page-listing static-page-listing1">
<ul class="products-grid">
<?php $num = 0; ?>
<?php foreach ($_categories as $_category): ?>
<?php if($_category->getIsActive()):
$num++;
$selImage = "SELECT value FROM catalog_category_entity_varchar WHERE attribute_id = '126' AND entity_id = '".$_category->getId()."'";
$catImage = Mage::getSingleton('core/resource')->getConnection('core_read')->fetchOne($selImage);
if(!$catImage) $catImage = "no_image.jpg"; ?>
<li class="category-item <?php if($num%2==0) echo 'item-right'?>">
<a href="<?php echo $this->getCategoryUrl($_category) ?>">
<div style="float:left; width:100%;">
<img src="<?php echo $category_path.$catImage?>">
</div>
<div>
<h3><?php echo $this->htmlEscape($_category->getName()) ?></h3>
<h6 style = "color:red;">VIEW ALL</h6>
</div>
</a>
</li>
<?php endif; ?>
<?php endforeach ?>
</ul>
</div>
<?php endif; ?>
NEW UPDATE:
The below code works:
<?php echo $cur_category->getDescription(); ?>
However, you need to be sure to check your Scopes! Not realizing my individual Store Scopes were not checked off to follow the "All Scopes" default, I fixed that and the above code worked for me when added to the "DESCRIPTION" area!
Thanks Stack!
PREVIOUS UPDATE:
I now have code working that I found online, it involved me adding a function to pull the category thumbnail image. It works! Here is the mark-up for the template:
<div class="category-products">
<ul class="products-grid">
<?php
$_categories=$this->getCurrentChildCategories();
if($_categories->count()):
$categorycount = 0;
foreach ($_categories as $_category):
if($_category->getIsActive()):
$cur_category=Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_category);
$catName = $this->getCurrentCategory()->getName();
if ($categorycount == 0){
$class = "first";
}
elseif ($categorycount == 3){
$class = "last";
}
else{
$class = "";
}
?>
<li class="item <?=$class?>">
<a href="<?php echo $cur_category->getURL() ?>" title="<?php echo $this->htmlEscape($cur_category->getName()) ?>">
<img src="<?php echo $cur_category->getThumbnailUrl() ?>" width="100" alt="<?php echo $this->htmlEscape($cur_category->getName()) ?>" />
</a>
<h2>
<a href="<?php echo $cur_category->getURL() ?>" title="<?php echo $this->htmlEscape($cur_category->getName()) ?>">
<?php echo $this->htmlEscape($cur_category->getName()) ?>
</a>
</h2>
<p>
DESCRIPTION
</p>
</li>
<?php
endif;
if($categorycount == 3){
$categorycount = 0;
echo "</ul>\n\n<ul class=\"products-grid\">";
}
else{
$categorycount++;
}
endforeach;
endif;
?>
</ul>
Now, where you see "DESCRIPTION," I would like to pull the category description data from the backend and have it output there. Basically, allowing dynamic creation/revision of top-level category pages.
How can I pull the description though? I'm not an expert in Magento, maybe I'm missing something basic but I can't get it working.
Thank you!
I am really newbie to Magento. I have this piece of code to show top menus.
<?php $_menu = $this->renderCategoriesMenuHtml(0,'level-top') ?>
<div class="nav-container">
<ul id="nav">
<li class="level0 first homelink"><span><?php echo $this->__('Home') ?></span></li>
<?php if($_menu): ?>
<?php echo $_menu ?>
<?php endif ?>
<?php $additionalLink = themeOptions('additionalLink'); ?>
<?php $additionalLinkUrl = themeOptions('additionalLinkUrl'); ?>
<?php if($additionalLinkUrl && $additionalLink): ?>
<li class="level0 clearence"><span><?php echo $additionalLink ?></span></li>
<?php endif ?>
</ul>
</div>
Now this is showing only Home as menu. I want to show other menus like about us,contacts,
and there will be also some categories with sub categories. I want my menu should look like this
http://8theme.com/demo/decostore/ . So can someone kindly tell me how to do this? Any help and suggestions will be really appreciable. Thanks
Here you have use the Top Menu (already created) in theme Folder /template/page/html/topMenu.phtml file
here includes the Categories and also the Custome url set using with blocks
This should be simple to achieve but since I'm a mage noob ((( I cant seem to get this to work.
I basically have category with all brands and what I'd like to do is to display brand names and links (without images) on the separate CMS page (brands).
Thanks.
Assuming the category you created has sub categories that are the brands, replace x with the id of your shop by brand category.
<?php
$brands = Mage::getModel('catalog/category')->load(x)->getChildrenCategories();
?>
<?php foreach($brands as $brand): ?>
<ul>
<li>
<a href="<?php echo $brand->getUrl() ?>">
<?php echo htmlspecialchars($brand->getName()) ?>
</a>
</li>
</ul>
<?php endforeach ?>