Magento :: Categories and Subcategories - php

Please anyone can help me how to design category and subcategory listing as below
http://www.officemax.com.au/office-supplies/writing.html
PS:: Magento default design is when you click a category it will list all products in that category straight. What I really want to do is , it should list all the subcategories first in the page like the above sample site http://www.officemax.com.au/office-supplies/writing.html and then list all relevent products of that subcategories
I will greatly appreciate if some one can help me.

Sub Categories within Categories - This is sample, you should customize
1.- Create a page called subcategory.phtml in the app/design/frontend/base/default/template/catalog/navigation folder and add following code piece :
<?php $_categories = $this->getCurrentChildCategories(); ?>
<?php foreach ($_categories as $_category): ?>
<?php if($_category->getIsActive()): ?>
<?php echo $this->htmlEscape($_category->getName()) ?>
<?php endif; ?>
<?php endforeach; ?>
2.- Create a static block called "MySubcategory" and put the following code into content :
{{block type="catalog/navigation" template="catalog/navigation/subcategory.phtml"}}
3.- Now go to category which you would like to use to show sub categories and ensure that category not set as an "anchor". In the display option tab, set it to show as "Static Block Only" and choose the block "MySubcategory"

Use Easy Catalog Images module:
http://www.magentocommerce.com/module/1562/magento-easy-catalog-images

Related

How to print the link of a category into the href="" of an anchor tag in Wordpress?

Ok so in my header.php file of my wordpress theme I have a navigation bar as shown below.
<nav>
Design
Tech
Photography
Film
Gaming
Motion
Lifestyle
Coding
Business
Other
</nav>
What I want to do is have a wordpress code that inserts the link to the page containing a list of all the categorys, in my case with the current permalink setup mine looks like this "www.example.com/design/post-name" so I essentially want it to link to "www.example.com/design" when the code is inserted into the anchor tag as shown below.
Design
Any help is appreciated! :)
Jamie
You need to get the category object and then use a foreach loop to build your list.
This should work for you:
<?php $categories = get_categories(); ?>
<nav>
<?php foreach ($categories as $category):?>
<?php echo $category->name;?>
<?php endforeach; ?>
</nav>

Can I give my own custom link to some categories in wp - ecommerce?

I am using Mazine template demo which is using wp-ecommerce plugin, In my website I have setup left Categories and Brands widgets, What I need is to link some of categories/Brands to link to my own custom URLs instead of opening category page.
Can I do that? Which specific file I need to change to achieve this?
Thanks
At last got the solution,
Just Edit wpsc-category_widget.php file under Mazine folder , and added some conditions to change the link of some of categories.
<?php if($ti_curr_cat['name']=="Category Name"){ ?>
<?php echo $ti_curr_cat['name']; ?>
<?php }else{?>
<?php echo $ti_curr_cat['name']; ?>
<?php }?>
I've been using http://ecommerceshoppingcart4u.com to build an ecommerce site. It only involves a one off payment which is very cheap. The price is £267

Display all products of a sub-category on a new or existing phtml page when clicking on a sub-category from Magento home-page

I have displayed all parent categories and sub-categories in the home page (left.phtml).
I want each sub-category to be a link which directs to a page where the products of that sub-category should be listed.
Nothing is working right now.
<?php $children = Mage::getModel('catalog/category')->getCategories($id); ?>
<ul
<?php foreach ($children as $category) { ?>
<li>
<?php echo $category->getName() ?> (<?php echo $category->getProductCount() ?>)</li>
<?php } ?>
</ul>
<?php } ?>
When clicking on the sub-category, it gives page not found error. Also nothing is showing in the getProductCount. What link should be given inside <a href=""> of sub-categories or where should this link be redirected to? From which phtml page the results are displayed.
I found lot of posts and articles regarding display products with categories and sub-categories. But couldn't find a solution for my issue (may be lack of searching skill).
Mage::getUrl('catalog/category/view', array('id', $category->getId()));
This code is untested, but I believe it will return the correct url. If it doesn't, post the url you're seeing.

Get the category name,permalink and description

So I need to list some categories, and I can list them with wp_list_categories but i also need the description for that category, i need to do something like this:
Category name
The description here
And right now I'm stuck i don't know how to do this with wordpress
This page shows how to add the Category Description: http://codex.wordpress.org/Function_Reference/category_description
It should have everything you need there, but for quick reference, the simplest way is:
<?php echo category_description(); ?>
(within the Wordpress loop)
EDIT
Just realized since you're combining this with wp_list_categories(), you'll have to create a loop that goes through the categoriy lists and displays the title and the description.
Try this Wordpress support page: http://wordpress.org/support/topic/have-wp_list_categories-output-the-category-descpription
Solved:
<?php
foreach(get_categories() as $category):
echo $category->cat_name;
echo category_description($category->cat_ID);
endforeach;
?>

Hide categories that have no products magento

I have many sites that use the same root category of the Main Site. Each product that is added is added to the site it was added to (wow.) and also the Main Site. However, I would like categories on a per site basis to only appear if there are products on that site.
If I have:
Category1
Category2
Category3
But Site1 only has products in Category1 and Category2, whereas Site2 and Site3 have products in Category2 and Category3; I only want Category1/2 to appear on Site1 and only Category2/3 to only appear on Site2 and Site3.
However, because all products in Site1/2/3 are also added to the Main Site; the Main Site would list Category1/2/3.
No products are added directly to the Main Site. It simply serves as a repository for the other sites.
Now, if there is no really easy way to enable this (as I'm sure), would it be as simple as writing my own theme that lists categories that only have products on the site that the template is being displayed on?
I am not a novice in the technologies that Magento uses; so writing custom code is no problem. I would, however, not like to edit it that much so that upgrading my code base would be easier in the future with later versions of Magento.
Thanks,
-nelson
Well, what you can do is, create your own helper with a collection (through a model), and then filter the collection based on product count.
Only a rough draft, but I've posted some code in another magento related question: Magento products by categories. You can see how and when it adds the products count, I'd filter again when this is done.
I don't think this is extremely "great" in terms of performance, so instead of using their model classes, you could write your own, extending it and adding default filters, or shortcutting directly to the database.
As long as you stay in your skin/template, there are no larger issues with updating.
this is a simple solution to hide categories that might help you .
The original contents of the top.phtml file should look like below.
<?php $_menu = $this->renderCategoriesMenuHtml(0,'level-top') ?>
<?php if($_menu): ?>
<div>
<ul id="nav">
<?php echo $_menu ?>
</ul>
</div>
<?php endif ?>
Replace the code above with this code below.
<?php $_menu = ''?>
<?php $excludeCat = array(); ?>
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php if($_category->getProductCount() <=0) {
$excludeCat[] = $_category->getId();
}
?>
<?php $_menu .= $this->drawItem($_category) ?>
<?php endforeach ?>
<?php if ($_menu): ?>
<div>
<ul id="nav">
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php if (!in_array($_category->getId(), $excludeCat)) : ?> <?php echo $this->drawItem($_category) ?>
<?php endif; ?>
<?php endforeach ?>
</ul>
</div>
<?php endif; ?>

Categories