Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 2
Finding catergory id’s
 
Concept
Jr. Member
 
Total Posts:  25
Joined:  2008-06-03
Worcestershire
 

Hello,

Where can I find the catergory ID’s for my sites catergories.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
harry12bar
Sr. Member
 
Avatar
Total Posts:  168
Joined:  2008-01-07
 

Hi, look in your admin in the category, there you will find the id number in the url.
cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
Concept
Jr. Member
 
Total Posts:  25
Joined:  2008-06-03
Worcestershire
 

OK Thanks,

Is there no where i can get a list off all the catergory ID’s without going into every catagory? I keep thinking I saw something about a Catergory Tree but cant find it now?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
David Oliver
Sr. Member
 
Avatar
Total Posts:  177
Joined:  2008-04-16
Cologne, Germany
 

If you take a look at your ‘catalog_category_entity_varchar’ table in the database and look at all the entries with an attribute_id of 31 (at least that’s what it’s like in my store) I think you’ll find what you want.

 
Magento Community Magento Community
Magento Community
Magento Community
 
internezzo ag
Jr. Member
 
Avatar
Total Posts:  17
Joined:  2008-05-19
Switzerland
 
harry12bar - 01 September 2008 08:30 AM

Hi, look in your admin in the category, there you will find the id number in the url.
cheers

Since version 1.1.5 or 1.1.6 it’s no longer in the URL. Now I have to look in the DB. Cumbersome…

 
Magento Community Magento Community
Magento Community
Magento Community
 
internezzo ag
Jr. Member
 
Avatar
Total Posts:  17
Joined:  2008-05-19
Switzerland
 

Hi all

I found a simpler way: Install and activate the “Tamper Data” Firefox extension.
Now click on a category. In Tamper Data you will see the URL containing the category ID (as seen in the browser address bar in earlier versions of Magento).

Hope this helps someone…

Regards

 
Magento Community Magento Community
Magento Community
Magento Community
 
PandaWebStudio
Member
 
Avatar
Total Posts:  40
Joined:  2008-04-19
Amsterdam, Netherlands
 
Concept - 04 September 2008 02:08 AM

OK Thanks,

Is there no where i can get a list off all the catergory ID’s without going into every catagory? I keep thinking I saw something about a Catergory Tree but cant find it now?

Thanks

Here is a code that displays all the categories ids:

<?php
    
require_once 'app/Mage.php';
        
Mage::app('default');
        
        
        
$categories Mage::getModel('catalog/category')->getCollection();
        
$categ_ids=$categories->getAllIds();
        
var_dump($categ_ids);
?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
JKwan13
Member
 
Total Posts:  63
Joined:  2008-06-12
 

Also take a look at this thread: http://www.magentocommerce.com/boards/viewthread/17998/

It seems you can now just go to Admin -> Catalog -> URL Rewrite.  If you have many categories (like I do), you can just type in name of your category in the “Request Path” to filter the list and you can see it in the “Target Path”.

 
Magento Community Magento Community
Magento Community
Magento Community
 
redhotrobbie
Jr. Member
 
Total Posts:  27
Joined:  2008-10-27
 

the URL Rewrite didnt display the root category id.  (why not?) So had to use the ‘dirty fix’.  Why does noone display the address of the code they publish???  app/design/adminhtml/default/default/template/catalog/category/edit/form.phtml i think

 
Magento Community Magento Community
Magento Community
Magento Community
 
Unirgy
Guru
 
Avatar
Total Posts:  478
Joined:  2007-09-07
 

If you’re looking to import categories using dataflow, try this solution:

http://www.magentocommerce.com/wiki/how_to_import_category_structure_with_products_using_dataflow

 
Magento Community Magento Community
Magento Community
Magento Community
 
davidgrun
Sr. Member
 
Total Posts:  245
Joined:  2008-07-10
 

Here is a code that displays all the categories ids:

<?php
    
require_once 'app/Mage.php';
        
Mage::app('default');
        
        
        
$categories Mage::getModel('catalog/category')->getCollection();
        
$categ_ids=$categories->getAllIds();
        
var_dump($categ_ids);
?>

This is a great piece of code!
How do I get the name of each category to be displayed next to each category ID and insert a line break <br /> after each one.

Example:

Cat. Name1: ID#1
Cat. Name2: ID#2
Cat. Name3: ID#3
....

THANKS!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
PandaWebStudio
Member
 
Avatar
Total Posts:  40
Joined:  2008-04-19
Amsterdam, Netherlands
 
davidgrun - 03 December 2008 04:49 AM

Here is a code that displays all the categories ids:

<?php
    
require_once 'app/Mage.php';
        
Mage::app('default');
        
        
        
$categories Mage::getModel('catalog/category')->getCollection();
        
$categ_ids=$categories->getAllIds();
        
var_dump($categ_ids);
?>

This is a great piece of code!
How do I get the name of each category to be displayed next to each category ID and insert a line break <br /> after each one.

Example:

Cat. Name1: ID#1
Cat. Name2: ID#2
Cat. Name3: ID#3
....

THANKS!!

Here is the code:

$categories_collection Mage::getModel('catalog/category')->getCollection();
        
$categories_collection->addAttributeToSelect('name')->setStoreId(Mage::app()->getStore()->getId())->load();    
    if(
$categories_collection->getSize()){
        
foreach($categories_collection as $category){
            
echo $category->getName().' '.$category->getId().'<br />';
        
}
    }
 
Magento Community Magento Community
Magento Community
Magento Community
 
davidgrun
Sr. Member
 
Total Posts:  245
Joined:  2008-07-10
 

@ab.wdev

Thanks for your help!
I’m getting this error with your new code.

Fatal error: Class ‘Mage’ not found in /home/kehothhh/public_html/category_id_list.php on line 9

This is my code.

<?php 
/*
DISPLAY CATEGORY IDs with names
*/

$categories_collection Mage::getModel('catalog/category')->getCollection();
        
$categories_collection->addAttributeToSelect('name')->setStoreId(Mage::app()->getStore()->getId())->load();    
    if(
$categories_collection->getSize()){
        
foreach($categories_collection as $category){
            
echo $category->getName().' '.$category->getId().'<br />';
        
}
    } 
?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
PandaWebStudio
Member
 
Avatar
Total Posts:  40
Joined:  2008-04-19
Amsterdam, Netherlands
 
davidgrun - 21 December 2008 06:02 PM

@ab.wdev

Thanks for your help!
I’m getting this error with your new code.

Fatal error: Class ‘Mage’ not found in /home/kehothhh/public_html/category_id_list.php on line 9

This is my code.

<?php 
/*
DISPLAY CATEGORY IDs with names
*/

$categories_collection Mage::getModel('catalog/category')->getCollection();
        
$categories_collection->addAttributeToSelect('name')->setStoreId(Mage::app()->getStore()->getId())->load();    
    if(
$categories_collection->getSize()){
        
foreach($categories_collection as $category){
            
echo $category->getName().' '.$category->getId().'<br />';
        
}
    } 
?>

Try this:

<?php
require_once 'app/Mage.php';
        
Mage::app('');

$categories_collection Mage::getModel('catalog/category')->getCollection();
        
$categories_collection->addAttributeToSelect('name')->setStoreId(Mage::app()->getStore()->getId())->load();    
    if(
$categories_collection->getSize()){
        
foreach($categories_collection as $category){
            
echo $category->getName().' '.$category->getId().'<br />';
        
}
    } 
?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
davidgrun
Sr. Member
 
Total Posts:  245
Joined:  2008-07-10
 

THANKS that works!

Here is my final code with a tad of styling just to make it easier to the eye wink

I also attached the file for whoever wants to download it. (just place it in your root folder).

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<
head>
    <
meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <
title>List Categories</title>
    <
style type="text/css">
    <!--
        .
row{border:1px solid #999; padding:2px;}
        
div.row{margin-bottom:2pxmargin-top:0px;}
        p{font
-family:verdanafont-size:12px;}
    
-->
    </
style>
</
head>

<
html><body>

<!-- List 
Categories' Names and IDs -->

<?php
require_once '
app/Mage.php';
        Mage::app('');

$categories_collection = Mage::getModel('
catalog/category')->getCollection();
        $categories_collection->addAttributeToSelect('
name')->setStoreId(Mage::app()->getStore()->getId())->load();    
    if($categories_collection->getSize()){
        foreach($categories_collection as $category){
            ?><div class="row"><p><b><?php echo $category->getName().'
:</b'.$category->getId().'</p></div>';
        }
    } 
?> 
</html></body>

Enjoy!

File Attachments
category_id_list.php  (File Size: 2KB - Downloads: 510)
 
Magento Community Magento Community
Magento Community
Magento Community
 
fortina
Jr. Member
 
Total Posts:  1
Joined:  2008-10-28
 

awesome bit of code… gonna save me having to enter all the products to find out the category IDs smile

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