jQuery- Parallax Scroll using jQuery

Parallax Scroll using jQuery

HTML:


Scroll Content 1
Scroll Content 2
Scroll Content 3
Scroll Content 4
Scroll Content 5
SCRIPT:
jQuery(function() {
  jQuery('a[href*=#]:not([href=#])').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {

      var target = jQuery(this.hash);
      target = target.length ? target : jQuery('[name=' + this.hash.slice(1) +']');
      if (target.length) {
        jQuery('html,body').animate({
          scrollTop: target.offset().top - 140
        }, 1000);
        return false;
      }
    }
  });
});

NOTE:

1. Please be sure, jQuery library has included for the page.

2. Put sufficient content section part.

Wordpress- hook to auto login after registration

Question: How can an user auto logged in after registration in wordPress? 
Answer: Using below hook/action/code, user will auto login after registration in wordPress.

 
function _new_user_auto_log_in($user_id){
  if(!is_user_logged_in()){
    $secure_cookie = is_ssl();
    $secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, array());
    global $auth_secure_cookie;
    $auth_secure_cookie = $secure_cookie;
   
    wp_set_auth_cookie($user_id, true, $secure_cookie);
    $user_info = get_userdata($user_id);
    do_action('wp_login', $user_info->user_login, $user_info);

  }
}
add_action('user_register', '_new_user_auto_log_in');

Wordpress - Update WordPress URLS in Database When Site is Moved to new Host

QUESTION: How we can change Change and Update WordPress URLS in Database When Site is Moved to new Host?

ANSWER: When migrating a WordPress site to a new URL either to a live production site or a testing development server, the new URL strings in the MySQL database need to be changed and updated in the various MySQL database tables.

First of all, we have do a MySQL database export of the old database on the old server, create a new blank database on the new server, import the old data either in PHPMyAdmin or mysql

After that we have to use below query as below. Also if needed change the table prefix values where applicable (i.e. wp_ )



 
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.new_url') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.new_url');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.new_url');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.new_url');
For reference :

Wordpress- How to Stay Logged in for Longer Periods

Question: How to stay logged in for longer periods in wordPress?
Answer: Using below hook/filter/code user will stay stay logged in for longer periods in wordPress.
 
// WordPress filter to Stay logged in for longer periods
add_filter( 'auth_cookie_expiration', 'keep_me_logged_in' );
function keep_me_logged_in( $expirein ) {
    return 31556926; // 1 year in seconds
}

SSH- How to export/import a MySQL database via SSH

Question: How can we export/import a MySQL database via SSH commands?

Answer: we can export/import a MySQL database using below commands.

USERNAME - the MySQL user assigned to your database.

DATABASE - the name of your MySQL database.

1. Exporting a MySQL database

mysqldump -uUSERNAME -p DATABASE > backup.sql 

2. Importing a MySQL database

mysql -uUSERNAME -p DATABASE < backup.sql 

Wordpress-What is the limitation to the depth of your categories?

Question: What is the limitation to the depth of your categories in WordPress?
Answer:  There is no limitation level to the depth.

Ajax- submit form using ajax (With file/ image)

Below is the HTML and script to submit form using ajax (With file/ image)

HTML

 
Image 1

Script

 
jQuery("form[name='uploader1']").submit(function(e) {
        var formData = new FormData(jQuery(this)[0]);
        jQuery.ajax({
            url: "http://your-domain/processupload.php",
            type: "POST",
            data: formData,
            async: false,
            success: function (msg) {
               // alert(msg)
                jQuery( "#success1" ).html(msg);
            },
            cache: false,
            contentType: false,
            processData: false
        });

        e.preventDefault();
    });

Note: Please be sure, jQuery libary has included for the page.

Magento 1.9 - Display New Products in Magento with Pagination

Display New Products in Magento with Pagination

Follow the following steps:

1. Create all of the folders/file in the following path if they do not already exist.
   app/code/local/Mage/Catalog/Block/Product/New.php

2. Put the below code on New.php
    <?php

    class Mage_Catalog_Block_Product_New extends Mage_Catalog_Block_Product_List
    {
       function get_prod_count()
       {
          //unset any saved limits
          Mage::getSingleton('catalog/session')->unsLimitPage();
          return (isset($_REQUEST['limit'])) ? intval($_REQUEST['limit']) : 12;
       }// get_prod_count

       function get_cur_page()
       {
          return (isset($_REQUEST['p'])) ? intval($_REQUEST['p']) : 1;
       }// get_cur_page

       /**
        * Retrieve loaded category collection
        *
        * @return Mage_Eav_Model_Entity_Collection_Abstract
       **/
       protected function _getProductCollection()
       {
          $todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);

          $collection = Mage::getResourceModel('catalog/product_collection');
          $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());

          $collection = $this->_addProductAttributesAndPrices($collection)
             ->addStoreFilter()
             ->addAttributeToFilter('news_from_date', array('date' => true, 'to' => $todayDate))
             ->addAttributeToFilter('news_to_date', array('or'=> array(
                0 => array('date' => true, 'from' => $todayDate),
                1 => array('is' => new Zend_Db_Expr('null')))
             ), 'left')
             ->addAttributeToSort('news_from_date', 'desc')
             ->setPageSize($this->get_prod_count())
             ->setCurPage($this->get_cur_page());

          $this->setProductCollection($collection);

          return $collection;
       }// _getProductCollection
    }// Mage_Catalog_Block_Product_New
    ?>

3. Put bellow lines on  app/design/frontend/default/your_theme/layout/catalog.xml

<reference name="content">
   <block type="catalog/product_new" name="product_new" template="catalog/product/list.phtml">
      <action method="setCategoryId"><category_id>10</category_id></action>
      <action method="setColumnCount"><column_count>6</column_count></action>
      <action method="setProductsCount"><count>0</count></action>
      <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
         <block type="page/html_pager" name="product_list_toolbar_pager" />
         <action method="setDefaultGridPerPage"><limit>12</limit></action>
         <action method="addPagerLimit"><mode>grid</mode><limit>12</limit></action>
         <action method="addPagerLimit"><mode>grid</mode><limit>24</limit></action>
         <action method="addPagerLimit"><mode>grid</mode><limit>36</limit></action>
         <action method="addPagerLimit"><mode>grid</mode><limit>48</limit></action>
         <action method="addPagerLimit" translate="label"><mode>grid</mode><limit>all</limit><label>All</label></action>
      </block>
      <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>6</count></action>
      <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
   </block>
</reference>
   
4.  Put bellow line on CMS page
{{block type="catalog/product_new" column_count="6" products_count="0" name="home.catalog.product.new" alias="product_homepage" template="catalog/product/list.phtml"}}

Njoy :)

Wordpress- Ajax Pagination (How to implement pagination on a custom WP_Query Ajax ?)

Question: How can we implement pagination on a custom WP_Query Ajax ?

Answer: We can follow the following steps.

1. Load More link.

Load More

2. Javascript: - Put this at the bottom of the file.

    var ajaxUrl = "";
    var page = 1; // What page we are on.
    var ppp = 3; // Post per page

    $("#more_posts").on("click",function(){ // When btn is pressed.
        $("#more_posts").attr("disabled",true); // Disable the button, temp.
        $.post(ajaxUrl, {
            action:"more_post_ajax",
           // offset: (page * ppp) + 1,
            offset: (page * ppp),
            ppp: ppp
        }).success(function(posts){
            page++;
            $(".name_of_posts_class").append(posts); // CHANGE THIS!
            $("#more_posts").attr("disabled",false);
        });
   });

3. Put this in the functions.php file.

function more_post_ajax(){
    $offset = $_POST["offset"];
    $ppp = $_POST["ppp"];
    header("Content-Type: text/html");

    $args = array(
        'post_type' => 'post',
        'posts_per_page' => $ppp,
        'cat' => 1,
        'offset' => $offset,
    );

    $loop = new WP_Query($args);
    while ($loop->have_posts()) { $loop->the_post();
       the_content();
    }

    exit;
}

add_action('wp_ajax_nopriv_more_post_ajax', 'more_post_ajax');
add_action('wp_ajax_more_post_ajax', 'more_post_ajax');

4. Enjoy :)

Wordpress- Disable update notification for individual single plugin

Question: How can we disable 'update notification' for individual single plugin in wordPress?
Answer: Using below filter we can disable 'update notification' for individual single plugin in wordPress.

/******/
/* Disable update notification for individual single plugin
/******/
function filter_plugin_updates( $value ) {
    unset( $value->response['akismet/akismet.php'] );
    return $value;
}
add_filter( 'site_transient_update_plugins', 'filter_plugin_updates' );

SSH- How to create php files in /var/www folder?

Question:  How can we create php files in /var/www folder using SSH command?
Answer:
-Create the file

sudo touch hello.php

-Open the file

sudo vi hello.php

Enter write mode (we were in command mode initially) by pressing  a  (note that    vi   is case sensitive)

After that, press Esc (to change to command mode) and type :wq Check if everything is fine with
cat hello.php

However, it's probably a better idea to use editors such as vim or nano as work with them is a lot simpler than that.

Wordpress- Contact form 7 : Validate comma separated urls

Question: How we can validate comma separated urls in for Contact form 7 plugin?

Answer: We can do this with contact form 7 filter.

For Example:

- If in form field is -

[textarea* yoururls]

- If we will put the url comma seperated .

- We can use below filter to custom validation in functions.php

add_filter( 'wpcf7_validate_textarea*', 'function_validate_urls', 20, 2 );
function function_validate_urls( $result, $tag ) {
    if ( 'yoururls' == $tag->name ) {
        $yoururls = isset( $_POST['yoururls'] ) ? trim( $_POST['yoururls'] ) : '';
        $error='noerror';
        $sepurl = explode(",",$yoururls);
        foreach($sepurl as $sep){
             $sep = preg_replace('/\s+/', '', $sep);
            if($sep!=''){
                if (filter_var($sep, FILTER_VALIDATE_URL)) {
                   // valid
                } else {
                    //invalid
                    $error= 'error';
                }
            }
        }
        if ( $error == 'error' ) {
           $result->invalidate( $tag, "Please check all urls in exact format." );
           // $result->invalidate( $tag, $error );
        }
    }

    return $result;
}