Call-back icon  Sales: Call 877.832.5289 (N America)|310.295.4144 (International)

Magento

eCommerce Software for Online Growth

Magento Forum

   
Page 1 of 2
A sitemap with the site structure? 
 
castus
Member
 
Total Posts:  40
Joined:  2008-06-05
 

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

Something like this > http://www.westcoweld.co.uk/site-map/index.htm

Has this been done to anyone’s knowledge?

 Signature 

Web Design Lincoln, UK

 
Magento Community Magento Community
Magento Community
Magento Community
 
Web Editors
Jr. Member
 
Avatar
Total Posts:  7
Joined:  2008-07-11
Temecula
 

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

<?php if($_items->getSize()): ?>
    
<div class="content">
        <
ul class="bare-list">
    
            
<?php foreach ($_items as $_item): ?>
            <?php
                $arg 
sizeof(split("/"$this->getItemUrl($_item)));
                
$pre_spacer '';
                
$spacer '&#149;';
                for(
$count 4$count $arg$count++ )
                
{
                    $pre_spacer 
$pre_spacer '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
        
}
                $spacer 
$pre_spacer '&#149;';
            
?>
                
<li><?=$spacer?> <a href="<?php echo $this->getItemUrl($_item) ?>"><?php echo $_item->name ?></a></li>
            
<?php endforeach; ?>
        
</ul>
    </
div>
<?php else: ?>

 Signature 

Alex Morales,
SEO Website Design - Web Editors

 
Magento Community Magento Community
Magento Community
Magento Community
 
7thSENSE.DE
Jr. Member
 
Avatar
Total Posts:  20
Joined:  2008-04-03
Reutlingen, Germany
 

Hi,

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:

File app/design/frontend/default/default/template/catalog/seo/sitemap.phtml

<?php foreach ($_items as $_item): ?>
    
<li class="sitemap_layer_<?= sizeof(split("/", $this->getItemUrl($_item))) ?>"><a href="<?= $this->getItemUrl($_item) ?>"><?$_item->name ?></a></li>
<?php endforeach; ?>

File skin/frontend/default/default/css/boxes.css:

.sitemap_layer_4{
    font
-weightbold;
}

.sitemap_layer_5{
    padding
-left15px;
}

.sitemap_layer_6{
    padding
-left30px;
    
font-styleitalic;
}

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?

The magento homepage show it right: http://www.magentocommerce.com/sitemap/

Cheerio!
Markus

 Signature 

Markus Schall

http://www.7thsense.de

 
Magento Community Magento Community
Magento Community
Magento Community
 
Web Editors
Jr. Member
 
Avatar
Total Posts:  7
Joined:  2008-07-11
Temecula
 

Markus,

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:

<?php foreach ($_items as $_item): ?>
            <? $class_name 
sizeof(split("/"$this->getItemUrl($_item))) - 3;    ?>
                
<li class="sitemap_level_<?=$class_name?>"><a href="<?= $this->getItemUrl($_item) ?>"><?$_item->name ?></a></li>
            
<?php endforeach; ?>

I also used the css file skin/frontend/default/default/css/custom.css: (enabled in page.xml)

.sitemap_level_1, .sitemap_level_3 {
    font
-weightbold;
    
font-size:14px;
}
.sitemap_level_2, .sitemap_level_4 {
    position
:relative;
    
left15px;
    
background:url(/skin/frontend/default/default/images/icon_rightarrowgray.gifleft 6px no-repeat;
    
padding:0 0 0 14px;
    
font-size:12px;
    
margin:0 0 0 4px;
}
.sitemap_level_3 {
    position
:relative;
    
left30px;
}
.sitemap_level_4 {
    left
45px;
}

I am not done with the cart yet, but you can see what I did at: http://www.sanctionedviolencegear.com/catalog/seo_sitemap/category/

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.

 Signature 

Alex Morales,
SEO Website Design - Web Editors

 
Magento Community Magento Community
Magento Community
Magento Community
 
Otaugames
Sr. Member
 
Total Posts:  101
Joined:  2007-10-07
Troyes, France
 

Thank you for the tip wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
ltd12
Jr. Member
 
Total Posts:  1
Joined:  2008-07-20
 

hi alex!

looks like you found a solution… i’m facing the same problem… could you post yours? that’ll be really great!

thx

jonathan

 
Magento Community Magento Community
Magento Community
Magento Community
 
7thSENSE.DE
Jr. Member
 
Avatar
Total Posts:  20
Joined:  2008-04-03
Reutlingen, Germany
 

Alex sitemap is ordered by name furthermore. in his case, the name-convention is fit to the sitemap wink

But i’ve found a solution:

edit app/code/core/Mage/Catalog/Block/Seo/Sitemap/Category.php:

$collection $helper->getStoreCategories('name'truefalse);
to
$collection $helper->getStoreCategories('path'truefalse);

it’s not the perfect listing of the categories, but it’s fit

 Signature 

Markus Schall

http://www.7thsense.de

 
Magento Community Magento Community
Magento Community
Magento Community
 
Web Editors
Jr. Member
 
Avatar
Total Posts:  7
Joined:  2008-07-11
Temecula
 

Markus,

Thank you I will have to try that out.

 Signature 

Alex Morales,
SEO Website Design - Web Editors

 
Magento Community Magento Community
Magento Community
Magento Community
 
gabrielk
Member
 
Avatar
Total Posts:  73
Joined:  2007-11-30
 
Web Editors - 18 July 2008 11:08 AM

.sitemap_level_2, .sitemap_level_4 {
    position
:relative;
    
left15px;
    
background:url(/skin/frontend/default/default/images/icon_rightarrowgray.gifleft 6px no-repeat;
    
padding:0 0 0 14px;
    
font-size:12px;
    
margin:0 0 0 4px;
}

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.gifleft 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

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dan Frydman
Jr. Member
 
Avatar
Total Posts:  8
Joined:  2008-05-20
 

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):

$tree $helper->getStoreCategories(true);

 Signature 

Managing Director
Inigo Media
Delivering Magento design and integration
+44 131 555 1147

 
Magento Community Magento Community
Magento Community
Magento Community
 
7thSENSE.DE
Jr. Member
 
Avatar
Total Posts:  20
Joined:  2008-04-03
Reutlingen, Germany
 

Great job Dan!

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

<?php $_items $this->getCollection(); ?>

<?php 
if($_items instanceof Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection): ?>

    <?php 
if($_items->getSize()): ?>
        
<div class="content">
            <
ul class="bare-list">
                
<?php foreach ($_items as $_item): ?>
                    
<li><a href="<?php echo $this->getItemUrl($_item) ?>"><?php echo $_item->name ?></a></li>
                
<?php endforeach; ?>
            
</ul>
        </
div>
    
<?php else: ?>
        
<div class="note-msg">
            
<?php echo $this->__('There are no %s available.'$this->getItemsTitle()); ?>
        
</div>
    
<?php endif ?>
    
<?php 
elseif($_items instanceof Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection): ?>

    
<div class="sitemap">
        
<?php echo $this->getShopTreeSitemap() ?>
    
</div>
    
<?php endif ?>

 Signature 

Markus Schall

http://www.7thsense.de

 
Magento Community Magento Community
Magento Community
Magento Community
 
UrKo
Jr. Member
 
Total Posts:  13
Joined:  2008-04-04
 

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?

thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
UrKo
Jr. Member
 
Total Posts:  13
Joined:  2008-04-04
 

would love to have it like magento has it...in two columns
http://www.magentocommerce.com/sitemap/

 
Magento Community Magento Community
Magento Community
Magento Community
 
cibernoid
Sr. Member
 
Avatar
Total Posts:  206
Joined:  2008-02-12
 
UrKo - 29 November 2008 12:46 AM

would love to have it like magento has it...in two columns
http://www.magentocommerce.com/sitemap/

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);
        
}
    }

 
Magento Community Magento Community
Magento Community
Magento Community
 
Leo27
Member
 
Total Posts:  51
Joined:  2008-10-08
 

Hi,
well it doesn’t work for me neither!

I’ve tried the 7thSENSE.DE tips, but nothing.

Does anyone actually make it work?
I’m using V1.1.6

Best regards
L. Nunes

 
Magento Community Magento Community
Magento Community
Magento Community
 
atlasit
Member
 
Avatar
Total Posts:  37
Joined:  2008-06-03
Los Angeles, CA
 

I’m having issues with this also.  It shows the pages and can click through, the content is doesn’t change between pages though.

 Signature 

If this saved you an hour, feel free to check out our website!  Atlas Consultant

or

Feed the addiction ;o)
Donate a cup of coffee!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 1 of 2