I would like to change the sitemap so that the structure of the web site is shown more accurately using static pages, categories, sub categories and products.
For example:
Home
Category
-- Sub category
---- product 1
---- product 2
About us
etc
I did not like the default layout of sitemap either so I decided to chage it to the exact way you are referring to - it makes sense to layout a sitemap this way.
I hope this helps! Cheers!
make changes in: app/design/frontend/default/default/template/catalog/seo/sitemap.phtml
good idea to count the separators, Alex. If you want to edit it by css for exact positioning or layout it with borders an background images, you can use code like this:
But the problem is, that the parent categories won’t fit to the subcategories, because the default sort order is (category-) name. how can i change this to see a accurate tree structure?
Absolutely ingenious! Not sure why i did not think about using CSS… doh! What you did is much better.
This is my first stab at Magento - switching from osCommerce.
To have the CSS class names reflect the correct level (for readability) here is what I did in app/design/frontend/default/default/template/catalog/seo/sitemap.phtml:
It would be nice to have the order reflect the structure in the main top navigation for the category site map. I am sure I can figure it out - I just need to find the source for the main nav and see what they did for the sitemap and make the modification… if someone has already done this it would be great if they can share it here.
I was just browsing through and thought I’d pitch in a couple tidbits..
- You can use a relative url in your css file so that the image isn’t glued to one particular theme / template.
background:url(../images/icon_rightarrowgray.gif) left 6px no-repeat;
...will always return the current skin’s icon_rightarrowgray.gif without having to hard-code the css.
- You may also want to consider generating the css inline with php. It won’t get cached by the browser, but you will always have the appropriate number of .sitemap_level_# classes for your formatting. Something like:
// Add a counter for $levels in the code that generates each level so it adds $levels++; // Then: foreach($i=1;$i<=$levels;$i++) { $padding=7*$i; echo '.style_level_'.$i.' {'."\n"; echo 'padding-left: '.$padding.'px'."\n"; echo '}'."\n"; } // end foreach
I was also a bit disappointed with the default generated sitemap for the shop categories and subcategories. I wanted something that displayed the sitemap in a tree structure, clearly showing the different categories and their subcategories. I came across this post whilst looking for a solution and although the template code by ‘Web Editors’ does work it didn’t make the correct use of nested ul tags.
In the end I wrote a small recursive function to generate the sitemap and have decided to add it here for the communities benefit.
function getShopTreeSitemap($tree = null) { // If no tree is given then initialise a top level tree // of all the categories and subcategories. if ($tree === null) { $helper = Mage::helper('catalog/category'); $tree = $helper->getStoreCategories(true); }
// The output assumes that there is always at least one // category at the top level. $output = '<ul>'; foreach ($tree as $category) { $output .= '<li><a href="/' . $category->getData('request_path') . '">' . $category->getData('name') . '</a>'; if ($category->hasChildren()) { $output .= getShopTreeSitemap($category->getChildren()); } $output .= '</li>'; } return $output . '</ul>'; }
The function will generate the sitemap using nested ul tags with no limit on the depth of the categories and subcategories. The sitemap has the same ordering as output by the shop but can be changed by altering the line (see here for the available options):
But i’ve seen one small bug. If you have deactivated categories, a html ul-li-tag is printed out and the names won’t show.
When you use this function in a Block, you must edit the line with the recursion, too.
this is a fixed code and you can use it in app/code/core/Mage/Catalog/Block/Seo/Sitemap/Category.php
public function getShopTreeSitemap($tree = null) { // If no tree is given then initialise a top level tree // of all the categories and subcategories. if ($tree === null) { $helper = Mage::helper('catalog/category'); $tree = $helper->getStoreCategories(true); }
// The output assumes that there is always at least one // category at the top level. $output = '<ul>'; foreach ($tree as $category) { if($category->getIsActive()){ $output .= '<li><a href="/' . $category->getData('request_path') . '">' . $category->getData('name') . '</a>'; if ($category->hasChildren()) { $output .= $this->getShopTreeSitemap($category->getChildren()); } $output .= '</li>'; } } return $output . '</ul>'; }
and now, call this instead of the old function in app/design/frontend/default/default/template/catalog/seo/sitemap.phtml
sorry to open old topic, but i tried everything u said here, but no luck. Im a total newbie and don’t know anything about php, so would it be possible to give me the code from start to finish which works?
I’d like to have it display with 2 columns as well. As far as i know the pagination is defined in app/code/core/Mage/Catalog/Block/Seo/Sitemap/Abastract.php but still i cannot figure it out.
public function bindPager($pagerName) { $pager = $this->getLayout()->getBlock($pagerName); /* @var $pager Mage_Page_Html_Pager */ if ($pager) { $pager->setAvailableLimit(array(50 => 50)); $pager->setCollection($this->getCollection()); $pager->setShowPerPage(false); } }