PHP or Magento Experts ... Please Help?

3 replies
Hey guys,

Basically I've got a vertical nav menu in a magento ecommerce site.

The code below is displaying the vertical nav menu the sub-categories
on the home page, but they're not hyperlinked (yet).

PHP Code:
<?php
 
Mage::getModel('catalog/category')->load(2)->getChildren();
 = 
explode(',',);
?>
<ul>
<?php foreach( as ): ?>
<li>
<?php
 
Mage::getModel('catalog/category')->load();
echo ();
 = 
Mage::getModel('catalog/category')->load(())->getChildren();
 = 
explode(',',);
?>
<?php 
if(count() > 1):?>
<ul>
<?php foreach( as ) :?>
<li>
<?php
 
Mage::getModel('catalog/category')->load();
echo ();
?>
</li>
<?php endforeach;?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
Apparently Im suppose to add this code somewhere so
it'll hyperlink the categories.

Here's the "instructions" that were given...

NOTE:
After loading each category you have a whole array of different attributes you can use. If you wanted to make each category listing be a link, simply use the getUrl() function in a similar fashion:
Here's the code...



Code:
 
 
#a href="<?php echo ()?>">    <?php echo ()?></a#

OK, seems as though the Warrior Forum wont allow me
to show you the code...

So if you could kindly check this site out,
all the code is there.

Magento Custom Category Listing Block | Devin R. Olsen Web Developer

There's a youtuibe video there as well, but
mentions nothing of the hyperlinking code.


Now, Im not sure if this is enough info, but Im pretty sure
a php expert could easily pick this up and whip their magic to give some much needed advice?

Any assistance would be greatly appreciated,
Thanks a bunch in advance,

- aj
#experts #magento #php
  • Profile picture of the author Havenhood
    I don't use Magento, but I believe you're looking for something like this:

    Now, for every occurrence of echo $category->getName(); use the code below:



    ?>

    <a href="<?php echo $category->getUrl()?>">

    <?php echo $category->getName()?>
    </a>

    <?php



    For every occurrence of echo $subCategory->getName(); use this code:


    ?>

    <a href="<?php echo $subCategory->getUrl()?>">

    <?php echo $subCategory->getName()?>
    </a>

    <?php



    Note:

    The author uses only the echo $category->getName(); to reference both the top and sub categories. That may be an oversight. Give that a try.
    Signature

    --= -Spazzle- =--

    {{ DiscussionBoard.errors[2963627].message }}
  • Profile picture of the author Aj Wilson
    Ray,

    You're a legend!

    Your solutions works ... but now magento is spitting out
    errors when clicking on the hyperlinks.

    Just wondering if this is the correct method?

    PHP Code:
    <?php
     
    Mage::getModel('catalog/category')->load(2)->getChildren();
     = 
    explode(',',);
    ?>
    <ul>
    <?php foreach( as ): ?>
     <li>
         <?php
        
    Mage::getModel('catalog/category')->load();
       
    ?>
    <a href="<?php echo ()?>"> 
    <?php echo ()?>
    </a>
    <?php 
        
    Mage::getModel('catalog/category')->load(())->getChildren();
        = 
    explode(',',);
      
    ?>
                <?php if(count() > 1):?>
                    <ul>
                    <?php foreach( as ) :?>
                        <li>
                        <?php
                             
    Mage::getModel('catalog/category')->load();
                            
    ?>
    <a href="<?php echo ()?>"> 
    <?php echo ()?>
    </a>
    <?php
                        ?>
                        </li>
                    <?php endforeach;?>
                    </ul>
                <?php endif; ?>
        </li>
    <?php endforeach; ?>
    </ul>

    or have I inserted them wrong?

    Thank you so much for your help mate,
    Signature
    {{ DiscussionBoard.errors[2964382].message }}
    • Profile picture of the author Aj Wilson
      Disregard Ray ....

      It was a magento issue.

      Thanks again for your assistance mate.
      Legend.

      - aj
      Signature
      {{ DiscussionBoard.errors[2965451].message }}

Trending Topics