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!
Related
This question is the duplicate of this one. None answer this question so far.
I am running a magento 1.9.1.0. And I have two stores, One is English and other one is Arabic.
My default store view is English in system --> manage stores. But in
the front end, arabic page is loading by default.
Why is it so? Any one can please help me with this?
You have set the locale in default configuration scope
admin > system > configuration > General > Locale Option > Locale
Check your language.phtml
If you are using flags instead of dropdown make sure you define the default language.
by using <?php if ($_lang->getCode() != 'default'): ?>
refer to complete code below
<?php if(count($this->getStores())>1): ?>
<div class="form-language">
<div class="langs-wrapper">
<?php foreach ($this->getStores() as $_lang): ?>
<?php if ($_lang->getCode() != 'default'): ?>
<?php $selected = $_lang->getId() == $this->getCurrentStoreId() ?>
<a class="lang-flag<?php $selected && print ' selected' ?>" href="<?php echo $_lang->getCurrentUrl() ?>">
<img src="<?php echo $this->getSkinUrl('images/flags/' . $_lang->getCode() . '.png');?>" alt="<?php echo $this->htmlEscape($_lang->getName()) ?>" height="16" width="24">
</a>
<?php endif;?>
<?php endforeach ?>
</div>
</div>
<?php endif;?>
Hi All I want to show 4 popular products on the home page of my magento 1.7.1 install. (The I can select by putting them into a category).
I've set this up by creating a hidden category called popularhome and added 4 products into it.
I've included this in a static block into my home page template by using:
{{block type="catalog/product_list" column_count="4" category_id="17" template="catalog/product/listhome.phtml"}}
My listhome.phtml template looks like this:
<div class="row popularproducts">
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<div class="alert fade in">
<a class="close" data-dismiss="alert">×</a>
<?php echo $this->__('There are no products matching the selection.') ?>
</div>
<?php else: ?>
<?php // List mode ?>
<?php if($this->getMode()!='grid'): ?>
<?php $_iterator = 0; ?>
<?php else: ?>
<?php // Grid Mode ?>
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<?php endif ?>
<div class="c3">
<?php if(($i-1)%$_columnCount==0): ?><?php elseif($i%$_columnCount==0): ?><?php endif; ?>
<div class="thumbnail">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(225); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<div class="caption">
<h2 class="product-name"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h2>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php endif; ?>
<?php echo $this->getPriceHtml($_product, true) ?>
</div>
</div>
</div>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
<?php endif ?>
<?php endforeach ?>
<?php endif; ?>
<?php endif; ?>
</div>
However this is only showing 2 of the 4 products yet I cannot figure out why? Does anyone see anything I am missing?
Thanks!
First you need to check ,the products that you want to be appear in category page,
Is they really belong to that categories.
After that make sure Backend > Manage Categories > Edit categories > Display settings >
is Anchor = yes Then re-index your catalog.
To verify you need to cross check catalog_category_product and catalog_category_product_index.
If the category id and product id is mapped properly in these tables you should be good to go.
hope this will sure help you!
I'm having a issue with my Magento not displaying the Best Selling products module because it doesn't seem to be processing the $product->name variable correctly.
The relevant code in mostpopular.phtml is:
<?php if($counter <= $totalPerPage): ?>
<?php $productUrl = $product->getProductUrl() ?>
<li>
<a href="<?php echo $productUrl ?>" title="View <?php echo $product->name ?>">
<?php echo $product->name ?>
</a>
</li>
<?php endif; $counter++; ?>
And then the HTML output is as below. The problem is the Title parameter in the < a> tag is missing the product name, and there is nothing between the < a>< /a> tags:
Site is running Magento 1.4.1.1
I don't work full-time on this stuff, so it's a bit above my head sometimes.
Try $product->getName() instead of $product->name
I have a featured product selection in pHtml, which instead of creating an attribute set in Magento, all i am doing is calling on a specific category (this is then added to the front end with XML ont he home page). It seems to work just fine, which is good. However when i try to call in the price I get nothing, i know Im not doing something right, but im just not sure what? here is my code:
<?php
$categoryid = 13;
$category = new Mage_Catalog_Model_Category();
$category->load($categoryid);
$collection = $category->getProductCollection();
$collection->addAttributeToSelect('*');
?>
<div class="featured-products group">
<h1 class="featured-header">Featured Products</h1>
<div >
<ul class="group multiple" id="featured-set-home">
<?php foreach ($collection as $_product) { ?>
<li>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(138); ?>" width="138" height="138" alt="" />
<?php echo $this->getTierPriceHtml(); ?>
<a href="<?php echo $_product->getProductUrl(); ?>" class="button right" ><span><span>View Item</span></span></a>
</li>
<?php } ?>
</ul>
</div>
</div>
Its not overly complicated. If anyone can help that would be awesome.
<?php echo $this->getTierPriceHtml(); ?>
Will get the price block (it must be added in the XML layout of the custom page that you have created)
I would just go for if you only need to show the price:
$this->helper('core')->currency(Mage::helper('tax')->getPrice($_product, $_product->getFinalPrice()), true, false)); ?>
I got a category page with list of subcategories in Magento. The list has an image and name, but I also want to display those subcategories' description. I tried simply to add
<strong><?php echo $this->htmlEscape($_category->getDescription()) ?></strong>
but it's not working.
EDIT: I get subcategories in a traditional way:
<?php if (!$_categoryCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no subcategories matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
<?php $_collectionSize = $_categoryCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_categoryCollection as $_category): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid">
<?php endif ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<a href="<?php echo $_category->getUrl() ?>" class="product-image"><img class="photo" src="<?php echo $this->getCategoryImage($_category, 214, 184); ?>" width="214" height="184" alt="<?php echo $_category->getName() ?>" />
<strong><?php echo $this->htmlEscape($_category->getName()) ?></strong>
<strong><?php echo $_category->getDescription() ?></strong>
</a>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
</div>
I've tried to update the public function getChildrenCategories($category) in the category.php file by adding ->addAttributeToSelect(’description’), but it's not working.
I can't see what exactly it is that you're doing wrong, but perhaps I can still help. I have successfully displayed the child category descriptions in list.phtml and you may be able to adapt what's working for me to your own purposes. The following is a stripped-down version of the code which works for me:
<?php $children = explode( ",", $this->getCurrentCategory()->getChildren() ); ?>
<div class="category-products">
<ul class="products-grid">
<?php foreach( $children as $child ): ?>
<?php $_child = Mage::getModel( 'catalog/category' )->load( $child ); ?>
<li class="item"><?php echo $_child->getDescription(); ?></li>
<?php endforeach; ?>
</ul>
</div>
The big difference between what you're doing and my sample above is that the getChildren() method on the catalog model object returns an array of category Ids and I then use the category Ids to load the corresponding child category model instances. My memory may be wrong here, but I seem to remember that the items returned from a Magento collection don't contain the full data that you get when you load by id.
I'm not sure if this will affect performance significantly or not (I would assume that loading a collection is faster than loading individual models) but it works so I'm not complaining...
Hope this helps.
Cheers,
Zac
I have relatively the same idea on the website I'm working on, where I display sub-categories in a grid view. While I used to use the method of individually loading category/product information by id's, I sort of fell in love with using the "Mage::getModel('')->getCollection()" method.
This is what I've used on my sub categories, and I've been quite happy with it, as it grabs all the information at once:
<?php
if(Mage::registry( 'current_category' )->getId()) {
$_currentCategoryId = Mage::registry( 'current_category' )->getId();
} else { //Get Root Category Id if not in a category
$_currentCategoryId = Mage::app()->getStore()->getRootCategoryId();
}
$_subCategories = Mage::getModel( 'catalog/category' )->getCollection()
->addAttributeToSelect('*')
->addFieldToFilter('parent_id',array('eq' => $_currentCategoryId))
->addFieldToFilter('include_in_menu',array('eq' => '1'))
->addFieldToFilter('is_active', array('eq' => '1'))
->addAttributeToSort('position', 'asc');
?>
<?php if(count($_subCategories) > 0): ?>
<!--This is where the sub-category layout would go.-->
<?php else: ?>
<!--Do something else if there are no sub-categories.-->
<?php endif; ?>
This will grab all visible sub-categories of the current category, OR grab the base categories (from Root Category Id) of the store, if you choose to have the template show on any other page. You could go further and define specific attributes with addAttributeToSelect as well.