Thursday, 15 November 2012

Creating jquery FAQ page in Magento

Most of the site need FAQ pages. We here going to demonstrate how we can achive with the help of simple Jquey script in Magento.
First create a FAQ page through Magento CMS by going to CMS Pages > Add New Page  in admin.
Add Sample content as :

<div class="expand_wrapper">
    <h2 class="expand_heading"><a href="#">1. WordPress Theme Development</a></h2>
    <div class="toggle_container">
        <div class="box">
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
        </div>
    </div>
    <h2 class="expand_heading"><a href="#">2. Magento E-commerce</a></h2>
    <div class="toggle_container">
        <div class="box">
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
            <p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
        </div>
    </div>
    <h2 class="expand_heading"><a href="#">3. Website Development</a></h2>
    <div class="toggle_container">
        <div class="box">
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
            <p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
        </div>
    </div>
    <h2 class="expand_heading"><a href="#">4. PHP MySql Development</a></h2>
    <div class="toggle_container">
        <div class="box">
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
            <p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
        </div>
    </div>
</div>
Now we need to add the Jquery specially for the CMS page.
Go to app/design/frontend/your-theme/layout
open the file cms.xml
Put the below code in default section of the cms.xml
<reference name="head">
    <block type="core/text" name="google.cdn.jquery">
        <action method="setText">
            <text><![CDATA[
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">jQuery.noConflict();</script>
<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery(".toggle_container").slice(1).hide();//expands first FAQ content
        jQuery(".expand_heading:first").addClass("active");//add active class to first FAQ title
        jQuery("h2.expand_heading").click(function(event){
            event.preventDefault()
            jQuery(this).toggleClass("active");
            jQuery(this).next(".toggle_container").slideToggle("slow");
        });
    });
</script>
 
            ]]></text>
        </action>
    </block>
</reference>
And that all, Now you can view the faq page going to www.yoursite.com/faq/
Courtesy: Magepsycho

1 comment :

  1. I like this weblog it's a master piece! Glad I found this on google.

    ReplyDelete