Friday, April 30, 2010

How to Display HTML/JavaScript Codes on Blogger Posts

Recently, a reader queried me this little doubt. How do I show the HTML/JavaScript codes on my Blogger posts? So, I decided to post it as a tidbit here.

Your HTML code has tags, enclosed in angle brackets (< and >). All you need to do is replace these angle brackets with these:

In place of <, use < and in place of >, use >. Keep everything else the same and publish your code, it will be shown as code itself on the published post.

Example:

In place of this code:
<a href="http://.com">yes</a>
you will use:
<a href="http://.com">yes</a>

Magento: Display Categories in Sidebar



It seems my posts lately are always in relation to solving a problem or answering a question for someone else. If you’re looking for a way to display categories in the sidebar, change category display, or create a category menu then this post is probably for you.

Creating the Block

The first thing you need to do is create a block in your layout. Navigate to /app/design/frontend/default/default/layout/catalog.xml
The first thing in your layout is a definition of the default layout noted by the comment “Default layout, loads most of the pages” depending on where you want to put your category nav (right sidebar, left sidebar, footer, etc) you’ll need to define the block a little differently. I’m going to do it with the left sidebar so you see what’s going on.

<reference name="left">
            <block type="catalog/navigation" name="catalog.leftnav" template="catalog/navigation/left_nav.phtml" />
</reference>


Okay, so what i did was locate the left sidebar which is referenced simply as “left” inside those tags i define my block type and template. The next thing you’ll want to do is create that template file, note that i defined it within /app/design/frontend/default/default/template/catalog/navigation/left_nav.phtml so i will need to create that file.

Creating the Template

Once I’ve created the file, it’s time to put in my code to populate my links automatically of all my categories:


<h2>Browse</h2>
<div class="block">
<ul id="nav_category" class="nav_category">
    <?php foreach ($this->getStoreCategories() as $_category): ?>
        <?php echo $this->drawItem($_category) ?>
    <?php endforeach ?>
</ul>
</div>
<?php echo $this->getChildHtml('topLeftLinks') ?>

 If you want to take this a step further, you can target subcategories based on current page with this little script (via Pratthost

<?php
$obj = new Mage_Catalog_Block_Navigation();
$store_cats    = $obj->getStoreCategories();
$current_cat     = $obj->getCurrentCategory();
$current_cat    = (is_object($current_cat) ? $current_cat->getName() : '');
 
foreach ($store_cats as $cat) {
    if ($cat->getName() == $current_cat) {
        echo '<li class="current"><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a>\n<ul>\n";
        foreach ($obj->getCurrentChildCategories() as $subcat) {
            echo '<li><a href="'.$this->getCategoryUrl($subcat).'">'.$subcat->getName()."</a></li>\n";
        }
        echo "</ul>\n</li>\n";
    } else {
        echo '<li><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a></li>\n";
    }
}
?>
 

Followers