Magento list of brand names on cms page - magento

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

Related

Left sidebar category navigation disappearing on last level category pages in Magento

On the lowest category levels, my sidebar is disappearing in Magento. Anchor is set to no for all my categories. Ultimately I want to display all main categories on sidebar (obviously on every product page) and the sub categories when inside a main category.
Not sure what the issue is. Pretty much base magento code with some style changes. Any help is much appreciated!
<?php if (!Mage::registry('current_category')) return ?>
<?php $_categories = $this->getCurrentChildCategories() ?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php if($_count): ?>
<aside id="sidebar">
<div class="sidebar-nav">
<h2><?php echo $this->__('Products') ?></h2>
<ul>
<?php foreach ($_categories as $_category): ?>
<?php if($_category->getIsActive()): ?>
<li>
<a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="current"<?php endif; ?>><?php echo $this->htmlEscape($_category->getName()) ?></a> (<?php echo $_category->getProductCount() ?>)
</li>
<?php endif; ?>
<?php endforeach ?>
</ul>
</div>
<div class="sidebar-nav">
<h2 class="red">Holiday</h2>
<ul>
<li>Christmas</li>
<li>Halloween</li>
<li>Thanksgiving</li>
<li>Easter</li>
<li>4th of July</li>
<li>Valentine's Day</li>
</ul>
</div>
<div class="sidebar-nav">
<h2>About Us</h2>
<ul>
<li>About Mary</li>
<li>Press</li>
<li>Licensing</li>
<li>Shows</li>
<li>Custom Work</li>
<li>Contact Us</li>
<li>Privacy Policy</li>
<li>Terms & Conditions</li>
</ul>
</div>
<script type="text/javascript">decorateDataList('narrow-by-list2')</script>
<?php endif; ?>
</aside>
They are disappearing on your lowest categories because your code is using:
<?php $_categories = $this->getCurrentChildCategories() ?>
If your current category (the category are you currently viewing) has no child categories, the block will not display any categories (because getCurrentChildCategories() returns the child categories of the current category).
The left categories will behave differently depending on whether the Is Anchor is set to Yes or No.
Category is set to Is Anchor: Yes
-The left categories will function as a filter, instead of a direct navigation link. When you click on a category on the left, you will remain in the same category you were viewing, however the results on the page will be filtered to the selected category.
Category is set to Is Anchor: No
-The left categories will function as a menu. When a category is selected, the user will be taken to that actual category page. If the category page they navigate to has no subcategories, no categories will appear on the left.
So in your case, you can set your upper level categories to Is Anchor: Yes and the lowest categories will act as filters instead of menu links.
If you want people to navigate to the lowest level subcategories, you will have to modify the functions the template uses to pull the categories from the parent category. There are several articles on StackOverflow already detailing how to do this.

How do I append WordPress category ID to image URL in my code?

I am coding a page that lists all of my categories, along with an image associated with that category. So far I am using this to create my list:
<?php
$args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($args);
?>
<ul id="category-list-grid">
<?php
foreach($categories as $cat) {
?>
<li><?php echo "<a href='" . get_category_link($cat->cat_ID) . "'> $cat->cat_name </a>" ?></li>
<?php
}
?>
</ul>
It works like a charm and displays a list of text links to each category. I want to take it one step further though and assign an image. Each image follows this naming convention:
category-[id].jpg (minus the brackets, of course)
I know what I need to do, just not how to do it. I want to add <img src="category-[code to insert cat id].jpg" border="0">
How do I do this? I am trying to avoid using a plugin as I am trying to keep the site as streamlined as possible.
Thanks!
Is this what you are looking for?
<img src="category-<?php echo $cat->cat_ID; ?>.jpg" border="0"/>
Edit to show full requested code:
<ul id="category-list-grid">
<?php foreach($categories as $cat){ ?>
<li>
<a href="<?php echo get_category_link($cat->cat_ID); ?>">
<?php echo $cat->cat_name; ?>
</a>
<img src="category-<?php echo $cat->cat_ID; ?>.jpg" border="0"/>
</li>
<?php } ?>
</ul>

Magento get categories and list in navigation in .phtml file

Ok so I've copied and pasted like 10 inserts already for php code to list the main categories or the sub categories under the Default root category.
None of them are displaying my categories and I have all my categories as root categories AND sub-categories under the Default root category to see if both scenarios will work..
Here is my php code I have in my theme .phtml file (1-column so far)
<?php $_categories = Mage::helper('catalog/category')->getStoreCategories(); ?>
<?php if (count($_categories) > 0): ?>
<ul>
<?php foreach($_categories as $_category): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
I know I have them setup right in the admin panel because I have them both as root and subcategories which shouldn't be necessary of course. I'm just trying everything to get them to display and nothing seems to be working..
Anyone know?
EDIT
Ok I found it in topmenu.phtml in the html directory under the template directory in the page directory:
<?php $_menu = $this->getHtml('level-top') ?>
<?php if($_menu): ?>
<div class="nav-container">
<ul id="nav">
<?php echo $_menu ?>
</ul>
</div>
<?php endif ?>
Where is the getHtml('level-top') code at so I can alter the markup of the li elements?
For change markup, you need rewrite protected _getHtml method in Mage_Page_Block_Html_Topmenu class

Magento how to show menus in top menu

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

Magento displays subcategories description on category list.phtml

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.

Resources