Add .html to the URL of WordPress Pages

There may be requirement to change the wordpress url. The permalinks options of wordpress maynot be sometime sufficient as per client specification. To get .html the post can be done by changing permalinks in admin , but adding .html extension in the page url is not done by it. For that just add the below lines in functions.php of your theme

add_action('init', 'html_page_permalink', -1);
register_activation_hook(__FILE__, 'active');
register_deactivation_hook(__FILE__, 'deactive');
function html_page_permalink() {
	global $wp_rewrite;
	if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){
		$wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
	}
}
add_filter('user_trailingslashit', 'no_page_slash',66,2);
function no_page_slash($string, $type){
	global $wp_rewrite;
	if ($wp_rewrite->using_permalinks() && $wp_rewrite->use_trailing_slashes==true && $type == 'page'){
		return untrailingslashit($string);
	}else{
		return $string;
	}
}
function active() {
	global $wp_rewrite;
	if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){
		$wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
	}
	$wp_rewrite->flush_rules();
}
function deactive() {
	global $wp_rewrite;
	$wp_rewrite->page_structure = str_replace(".html","",$wp_rewrite->page_structure);
	$wp_rewrite->flush_rules();
}

If you arenot intrested to do so then you can install this plugin from https://wordpress.org/plugins/html-on-pages/
Above code are also taken from the that plugin

If you want to get .php then then just change .html to .php on above code.

WordPress Permalinks on Windows IIS

Normally we host the wordpress site in linux hosting and everythings works fine with permalinks. But sometime server may be different , let say for the Windows IIS server the permalinks may not works hence resulting the URL that isnot SEO friendly. So to overcome this issue we need to create web.config in root directory and add the following code in the file.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="wordpress" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
Source : http://workfunc.com/how-to-setup-wordpress-permalinks-on-windows-iis/
search by category

Magento Adding search by category in advance search

Sometime we may need to change the options provided by the magento by default. Here are dealing with adding the “Search By Category” in the advance search page. For this case we need to change in the followinf files
➣ app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php
➣ app/code/core/Mage/CatalogSearch/Model/Advanced.php
➣ app/design/yourdesign/yourdesign/template/catalogsearch/advanced/form.phtml

At the very end of app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php (before the closing brace), add:

public function getStoreCategories()
{
    $helper = Mage::helper('catalog/category');
    return $helper->getStoreCategories();
}

In app/code/core/Mage/CatalogSearch/Model/Advanced.php, replace the getSearchCriterias() function (line 157) with the code below:

     public function getSearchCriterias()
        {
            $search = $this->_searchCriterias;
            /* display category filtering criteria */
            if(isset($_GET['category']) && is_numeric($_GET['category'])) {
                $category = Mage::getModel('catalog/category')->load($_GET['category']);
                $search[] = array('name'=>'Category','value'=>$category->getName());
            }
            return $search;
        }

replace the next function, getProductCollection(), with:

public function getProductCollection(){
        if (is_null($this->_productCollection)) {
            $this->_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
                ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
                ->addMinimalPrice()
                ->addStoreFilter();
                Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection);
                Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection);
            /* include category filtering */
            if(isset($_GET['category']) && is_numeric($_GET['category'])) $this->_productCollection->addCategoryFilter(Mage::getModel('catalog/category')->load($_GET['category']),true);
        }
 
        return $this->_productCollection;
    }

In app/design/yourdesign/yourdesign/template/catalogsearch/advanced/form.phtml, after this code:

 <?php foreach ($this->getSearchableAttributes() as $_attribute): ?>
        <?php $_code = $_attribute->getAttributeCode() ?>
            <label for="<?php echo $_code ?>"><?php echo $this->getAttributeLabel($_attribute) ?></label>
            <?php switch($this->getAttributeInputType($_attribute)):
                case 'number': ?>
                <div class="range field-row">
                    <input name="<?php echo $_code ?>[from]" value="<?php echo $this->htmlEscape($this->getAttributeValue($_attribute, 'from')) ?>" id="<?php echo $_code ?>" title="<?php echo $this->htmlEscape($this->getAttributeLabel($_attribute)) ?>"  class="input-text validate-number" type="text" />
                    <input name="<?php echo $_code ?>[to]" value="<?php echo $this->htmlEscape($this->getAttributeValue($_attribute, 'to')) ?>" id="<?php echo $_code ?>_to" title="<?php echo $this->htmlEscape($this->getAttributeLabel($_attribute)) ?>"  class="input-text validate-number" type="text"/>
                </div>
                <?php break;
                case 'select': ?>
                    <?php echo $this->getAttributeSelectElement($_attribute) ?>
                <?php break;
                case 'yesno': ?>
                    <?php echo $this->getAttributeYesNoElement($_attribute) ?>
                <?php break;
                case 'date': ?>
                    <?php echo $this->getDateInput($_attribute, 'from') ?>
                    -
                    <?php echo $this->getDateInput($_attribute, 'to') ?>
                <?php break;
                default: ?>
                <input name="<?php echo $_code ?>" id="<?php echo $_code ?>" value="<?php echo $this->htmlEscape($this->getAttributeValue($_attribute)) ?>" title="<?php echo $this->htmlEscape($this->getAttributeLabel($_attribute)) ?>"  class="input-text <?php echo $this->getAttributeValidationClass($_attribute) ?>" type="text" />
            <?php endswitch; ?>
        <?php endforeach; ?>

add:

            <label for="category_search_field">Search by Category:</label>
            <select name="category" id="category_search_field">
                <option value="">-- Any Category --</option>
                <?php foreach ($this->getStoreCategories() as $_category): ?>
                <?php if($_category->hasChildren()): ?>
                <option class="parent-cat" value="<?php echo $_category->getId(); ?>"><?php echo $_category->getName();?></option>
                <?php foreach ($_category->getChildren() as $subcategory):
                if($subcategory->getIsActive()) : ?>
                    <option value="<?php echo $subcategory->getId(); ?>"<?php echo ($this->getRequest()->getQuery('category') == $subcategory->getId() ? ' selected="selected"': "") ?>><?php echo $subcategory->getName(); ?></option>
                <?php endif; endforeach; ?>
                <?php elseif($_category->getIsActive()): ?>
                <option value="<?php echo $_category->getId(); ?>"><?php echo $_category->getName();?></option>
                <?php endif; ?>
                <?php endforeach ?>
 
            </select>

Then open app/code/core/Mage/CatalogSearch/Model/Advanced.php
Open the file and search this function addFilters. In this function you can see following codes, replace this

    if ($allConditions) {
                $this->getProductCollection()->addFieldsToFilter($allConditions);
            } else if (!count($filteredAttributes)) {
                Mage::throwException(Mage::helper('catalogsearch')->__('You have to specify at least one search term'));
            }

with following codes:

    if (($allConditions) || (isset($values['category']) && is_numeric($values['category']))) {
                $this->getProductCollection()->addFieldsToFilter($allConditions);
            } else if (!count($filteredAttributes)) {
                Mage::throwException(Mage::helper('catalogsearch')->__('You have to specify at least one search term'));
            }

After above steps is done you will get the output as below
search by category

Source : http://www.magentocommerce.com/wiki/5_-_modules_and_development/search_and_advanced_search/how_to_add_search_by_category_to_advanced_search

WordPress Turn Off Auto Update for Single Plugin

Wordpress Turn Off Auto Update for Single Plugin

WordPress Turn Off Auto Update for Single Plugin


While working with plugins sometimes we need to change the default values and attributes of the plugin which may be lost as soon as the plugin creator add the update to wordpress.
For to disable the auto update or hiide update message from the admin we can add the follwing line in finction.php .

function filter_plugin_updates( $value ) {    
unset( $value->response['plugin-directory-name/plugin-file.php'] );    
return $value;
}
add_filter( 'site_transient_update_plugins', 'filter_plugin_updates' );

Here plugin-directory-name is the plugin folder name you want to disable and plugin-file.php is the main file of the plugin.

Source : http://wordpress.stackexchange.com/questions/25358/turn-off-auto-update-for-single-plugin

Create a pop-up WordPress email contact form 7

Contact form 7 can be used for different kinds of forms. Sometimes we may need to show the form in popup display. For to show the contact form in popup we can simply install Easy fancybox  and Contact Form 7 from wordpress plugin directoy and simple configure as below,
Firstly create contact form as you required and place contact form shortcode as below

<a href="#contact_form_pop" class="fancybox">Contact Us</a>

<div style="display:none" class="fancybox-hidden">
    <div id="contact_form_pop">
        [contact-form-7 404 "Not Found"]
    </div>
</div>

For further detail you may visit to url below,

Source : http://geektastical.com/2011/05/how-to-create-a-pop-up-wordpress-email-contact-form/

Magento quantity increments using jQuery

If we need to add increments in the quantity then we can follow the below simple method .
First of all we need to add the jQuery code. Add the following to one of your jQuery js files (or create a new one if that’s your thing).

jQuery("div.quantity").append('<input type="button" value="+" id="add1" class="plus" />').prepend('<input type="button" value="-" id="minus1" class="minus" />');
        jQuery(".plus").click(function()
        {
            var currentVal = parseInt(jQuery(this).prev(".qty").val());
            
            if (!currentVal || currentVal=="" || currentVal == "NaN") currentVal = 0;
             
            jQuery(this).prev(".qty").val(currentVal + 1);
        });
     
        jQuery(".minus").click(function()
        {
            var currentVal = parseInt(jQuery(this).next(".qty").val());
            if (currentVal == "NaN") currentVal = 0;
            if (currentVal > 0)
            {
                jQuery(this).next(".qty").val(currentVal - 1);
            }
        });

Then Move the file app/design/frontend/base/default/template/catalog/product/view/addtocart.phtml into your theme directory if you haven’t already, open it up and look for line 34. You should see the code for the input which will look something like:

<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />

Change the AS BELOW

<div class="quantity">
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
</div>
Source : http://jigowatt.co.uk/blog/magento-quantity-increments-jquery-edition/

Eclipse – “Too many open files” Problem

If your OS is Linux and you are using Eclipse, you might possibly see the following error messages or similar on certain time. This may result by installing many plugin or other reasons.
This is because there are too many files opened and these are more files than the number of open files allowed . So Eclipse cannot open more files and displays the errors above.
Let’s see the number of open files.
$ lsof | wc -l

e.g.)

$ lsof | wc -l
9028

In my case, it was 9028.

Now check the limitation of open files

Now check the limitation of open files
$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 31226
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 31226
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

To change it, open the file /etc/security/limits.conf and put a greater number than 1024 depending on the number of open files you checked with lsof | wc -l just before.
For example,
Open the file
$ gksudo gedit /etc/security/limits.conf
add these lines
*                soft    nofile          9216

*                hard    nofile          9216

Log out and in then check with ulimit. It should show like this.
For more detail view in below page,

Source: http://blog.lckymn.com/2009/08/11/eclipse-too-many-open-files-problem/comment-page-1/

Customize WordPress login logo without a plugin

Sometime wordpress developer need to change the wordpress logo in admin login screen while creating the site for the client. For that we can simply include the code below and deploy it without using any plugin. Simply copy and paste the code below in the function.php of your theme folder.

function my_custom_login_logo() {
    echo '<style type="text/css">
        h1 a { background-image:url('.get_bloginfo('template_directory').'/images/custom-login-logo.gif) !important; }
    </style>';
}

add_action('login_head', 'my_custom_login_logo');

The image that need to changed should be placed in the images folder of the theme.

Source: http://www.wprecipes.com/customize-wordpress-login-logo-without-a-plugin

Magento – Display Address Fields on Create an Account

By default Magento doesnt show the address fields within “Create an Account”. To make the sign up process more user friendly you can enable the address fields by adding the following:
Simple way to show that is to add the below code in customer.xml or in local.xml

<customer_account_create>
        <reference name="customer_form_register">
            <action method="setShowAddressFields"><value>true</value></action>
        </reference>
</customer_account_create>
Source : http://www.pauldonnelly.net/magento-display-address-fields-in-create-an-account/ 

Customer cannot login to magento 1.8.1.0

Using the free theme sometime may result  of customer not logged in problem issue. To resolve this issue we need to put the for key field in the login form.
In app/design/frontend/default/…/template/persistent/customer/form/login.phtml , around line 41 should look like

 <form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">
 <?php echo $this->getBlockHtml('formkey'); ?> 

If the code is not seen then add it then customer login works