Magento Best Selling Products in homepage

Magento keeps tracks of the sold item , sometimes we need to displayed the most selled product in the homepage . So for that case i find the article while searching and i am using that article in this post.
Simply create directory as app/code/local/Mage/Catalog/Block/Product and create file Bestseller.php , and paste the following code.

class Mage_Catalog_Block_Product_Bestseller extends Mage_Catalog_Block_Product_Abstract
    public function __construct()

        $storeId    = Mage::app()->getStore()->getId();

        $products = Mage::getResourceModel('reports/product_collection')
            ->addAttributeToSelect(array('name', 'price', 'small_image', 'short_description', 'description')) //edit to suit tastes
            ->setOrder('ordered_qty', 'desc'); //best sellers on top



Now we need a template to use. So for that case create the file bestseller.phtml in your design folder as following order,
app/design/frontend/*/*/template/catalog/product/bestseller.phtml . Then paste the following code

 <?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
<div class="home-page-cntr">
<?php $i=0; foreach ($_products->getItems() as $_product): ?>
    <?php if ($i>5): continue; endif; ?>

<div class="home-page-item">
        <div class="home-page-img">
            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
                 <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(65,65); ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>"/>
            <?php echo $_product->getDescription(); //also getShortDescription ?>
        <div class="home-page-txt">
            <p><a class="product-name" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $_product->getName() ?></a></p>
            <?php //echo $this->helper('review/product')->getSummaryHtml($_product, 'short') //product review link ?>
            <?php echo $this->getReviewsSummaryHtml($_product, false, true)?>
            <?php //echo $this->helper('catalog/product')->getPriceHtml($_product) ?>
            <?php echo $this->getPriceHtml($_product) ?>
            <?php echo $_product->getProductId(); ?>
            <?php if($_product->getevent_date()) {echo $_product->getevent_date();} ?>
<?php $i++; endforeach; ?>
<?php for($i;$i%5!=0;$i++): ?>
    <?php endfor ?>
<?php endif; ?> 

To use this code, you need to add the block somewhere, either via XML or in a CMS page like your home page:
To use in a CMS page, use this where you enter your content – use it where you want to this item to show up!:

{{block type="catalog/product_bestseller"  template="catalog/product/bestseller.phtml"}}

Above code is tested and implemented in Magento

Source :

Changing WordPress’ Autosave Frequency and Post Revisions

WordPress has a very nifty autosave feature which can be a lifesaver to anyone who uses WordPress. The downside to WordPress’ autosave, is that it creates a bunch of draft posts increasing your mySQL database size, especially if you write the post within WordPress’ post editor.

If desired, it is possible to change WordPress’ autosave frequency, or even disable the WordPress autosave feature entirely. Furthermore, if you wish to disable WordPress’ post revisions, or limit the total number of post revisions, both are simple to do in WordPress.

The following code snippets will need to be placed in your WordPress install’s wp-config.php. It’s a simple copy and paste, but be careful. If you mess up your WordPress install’s wp-config.php, the WordPress site will break. If you break your WordPress site while editing the wp-config.php file, undo your changes and re-save your WordPress install’s wp-config.php file and everything should be fixed.

How to Change WordPress’ Autosave Frequency

Simply paste the following snippet in your WordPress install’s wp-config.php to change WordPress’ autosave frequency to save every 5 minutes. The integer is the total number of seconds between each autosave.

define('AUTOSAVE_INTERVAL', 300 );  // integer is in seconds

How to Disable WordPress’ Post Revisions

Simply paste the following snippet in your WordPress install’s wp-config.php to disable WordPress’ post revisions feature.

define('WP_POST_REVISIONS', false ); // disable post revisions

How to Limit WordPress’ Post Revisions

Simply paste the following snippet in your WordPress install’s wp-config.php to adjust the limit of WordPress’ revisions that are kept from WordPress’ autosave feature

define('WP_POST_REVISIONS', 3); // alter number of post revisions kept.


It’s that simple to change WordPress’ autosave frequency or even completely disable WordPress’ post revisions. Doing so will decrease the size of WordPress’ database, but will limit the ability to recover from mistakes. So this WordPress modification could come in handy, or cause problems. Be careful.

Source :

WordPress:Display a loading image until the page completes loading

To get the ajax loader image until the page loads ,
First add the following code somewhere in header.

<script src="" />
<div id="loading-image">
	<img src="<?php bloginfo('template_url'); ?>/images/ajax-loader.gif" alt="Loading..." />

Then , add the css for the styling purpose

#loading-image {
	background-color: #333;
	width: 55px;
	height: 55px;
	position: fixed;
	top: 20px;
	right: 20px;
	z-index: 1;
	-moz-border-radius: 10px;
	-webkit-border-radius: 10px;
	border-radius: 10px; /* future proofing */
	-khtml-border-radius: 10px;

Now finally add the jquery part in the footer,

jQuery(window).load(function() {

This can be used for magento site too , just need to change the portion that we include in header
Just add the line below in header.phtml

<script src="">
<div id="loading-image">
	<img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif', array('_secure'=>true)) ?>" alt="Loading..." />
Source :

WordPress : Fixing Pagination on Custom Queries With query_posts

First off, custom queries are good for calling or excluding certain posts to a page.  Lets say we want to display 5 posts per page from category 10.  The best place to learn how to do this is the Codex.  You would probably start after reading that article like this:

<?php query_posts('posts_per_page=5&cat=10'); ?>

Now technically this would be proper, and it would get you the results you are after, but there would be no pagination.  So if you had many posts and were trying to go to the next page, the same posts would still show.  Here’s how to fix that.  First off, I like to put all my args for query_posts into an array, it’s so much simpler to look at and organize.  So the above as an array would be:

<?php query_posts( array (
     'posts_per_page' => 5,
     'cat' => '10',

And that would work the same.  But it’s more organized to me, and so much easier to add more items.  Now  the answer to our problem.  We will take that above query array and get pagination working.

<?php query_posts( array(
     'posts_per_page' => 5,
     'cat' => '10',
     'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),

And there we have it!  I think that’s pretty simple.  Always include pagination within your custom query and you’ll be good to go!

UPDATE: Thanks to a reader, and a little scan through the codex, it looks like we may need to update the code above.

<?php query_posts( array(
     'posts_per_page' => 5,
     'cat' => '10',
     'paged' => ( get_query_var('page') ? get_query_var('page') : 1 ),
Source :

Redirecting non-www to www with .htaccess and vice-versa

If you want to redirect all non-www requests to your site to the www version, all you need to do is add the following code to your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

This will redirect any requests to to There are several benefits from doing that:

  • It will avoid duplicate content in Google
  • It will avoid the possibility of split page rank and/or split link popularity (inbound links).
  • It’s nicer, and more consistent.

Note that if your site has already been indexed by Google without the www, this might cause unwanted side effects, like lost of PR. I don’t think this would happen, or in any case it would be a temporary issue (we are doing a permanent redirect, 301, so Google should transfer all rankings to the www version). But anyway, use at your own risk!

Something nice about the code above is that you can use it for any website, since it doesn’t include the actual domain name.

Redirecting www to non-www

If you want to do the opposite, the code is very similar:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^my-domain\.com$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

In this case we are explicitly typing the domain name. I’m sure it’s possible to do it in a generic way, but I haven’t had the time to work one out and test it. So remember to change ‘my-domain’ with your domain name!
If your want more detail visit the source i have copied from.

Source :

WordPress : Front end form submit with jquery form plugin

I have used used the jquery form and tried submitting the form in wordpress but it results in error , form post value is not shown . After long reseach i got the solution about it , form data submission is cannot be done as we normally do in php. For wordpress we need to define the function in function.php of our theme and perform the desire action. I we can to use form as

<form id="myForm"action=""method="post"> 
Name: <inputtype="text"name="name"/> 
Comment: <textareaname="comment"></textarea>
<inputtype="submit"value="Submit Comment" name="form_sub"/>

Then add the following code to your

add_action('init', 'form_submit');

function form_submit(){
        //here you'll have your form data in a $_POST array, you can check it using a print_r. parse the form and insert the post
        $title = $_POST['name'];
        $content = $_POST['comment'];

        //change the category and author as you want
        $post_obj = array(
                        'post_title' => $title,
                        'post_content' => $content,
                        'post_category' => array(1), //Uncategorized
                        'post_status' => 'draft',
                        'post_author' => 1 //Admin
        $id = wp_insert_post($post_obj);

        //check if successfully submitted
        if(isset($id) && !is_wp_error($id))
            //redirect to a thank you page, make sure the slug is 'thank-you'
Source :