Tuesday, 18 September 2018

How to create jQuery fadeIn fadeOut Animation

How to create jQuery fadeIn fadeOut Animation

Html:
<ul>
<li class="client-testimonial"><img src="demo1.png"></li>
<li class="client-testimonial"><img src="demo2.png"></li>
<li class="client-testimonial"><img src="demo3.png"></li>
<li class="client-testimonial"><img src="demo4.png"></li>
</ul>


jQuery:

jQuery(document).ready(function(){
if(jQuery('.client-testimonial').length > 0){
var showImg = jQuery(".client-testimonial-img");
var quoteIndex = -1;

function showFadeInFadeOut() {
++quoteIndex;
showImg.eq(quoteIndex % showImg.length)
.fadeIn(2000)
.delay(2000)
.fadeOut(2000, showFadeInFadeOut);
}
showFadeInFadeOut();
}

});

Wednesday, 12 September 2018

How to get custom image size url in Wordpress

Here are simple way to get custom image from URL

$imgUrl = 'http://localhost/wptest/wp-content/themes/sydney/images/header.jpg';

 
global $wpdb;
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $imgUrl ));
$image_id = $attachment[0];
$thumbnail_url = wp_get_attachment_image_src($image_id, array('615','440'), true );

Monday, 3 September 2018

How to set varchar primary key field in Mysql

How to set varchar primary key field in Mysql

Table structure of Users table

CREATE TABLE `users` (
   `id` varchar(36) NOT NULL DEFAULT 'InitiallyEmpty',
   `first_name` varchar(100) NOT NULL,
   `last_name` varchar(100) NULL,
   `email` varchar(100) NOT NULL,
   `password` varchar(100) NOT NULL,
   PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

Want to fill id an automatically filled. You need to create trigger


Trigger structure for automatically update

DROP trigger if exists before_insert_users;
delimiter $$
CREATE TRIGGER before_insert_users
BEFORE INSERT ON users
FOR EACH ROW
BEGIN
    SET new.id = uuid();
END $$

delimiter ;

Now create insert query

insert into users (first_name,last_name,email,password) values ('Sudhir','Pandey','psudhir20@gmail.com','123465');

Thursday, 19 July 2018

How to Add Next Previous links to The Event Calendar

Add Next/Previous links to The Event Calendar Wordpress Plugin

Add code to your child theme’s functions.php file

/**
 * Allows visitors to page forward/backwards in any direction within month view
*/

if ( class_exists( 'Tribe__Events__Main' ) ) {

class ContinualMonthViewPagination {
    public function __construct() {
        add_filter( 'tribe_events_the_next_month_link', array( $this, 'next_month' ) );
        add_filter( 'tribe_events_the_previous_month_link', array( $this, 'previous_month' ) );
    }

    public function next_month() {
        $url = tribe_get_next_month_link();
        $text = tribe_get_next_month_text();
        $date = Tribe__Events__Main::instance()->nextMonth( tribe_get_month_view_date() );
        return '<a data-month="' . $date . '" href="' . $url . '" rel="next">' . $text . ' <span>&raquo;</span></a>';
    }

    public function previous_month() {
        $url = tribe_get_previous_month_link();
        $text = tribe_get_previous_month_text();
        $date = Tribe__Events__Main::instance()->previousMonth( tribe_get_month_view_date() );
        return '<a data-month="' . $date . '" href="' . $url . '" rel="prev"><span>&laquo;</span> ' . $text . ' </a>';
    }
}

new ContinualMonthViewPagination;

}

Monday, 2 July 2018

How to use registered post type Hook

How to use registered_post_type Hook and modify post type registration

Create custom post type hook for products inside function.php file

add_action( 'init', 'wpyog_register_products_cpt' );
/**
 * Register Products Custom Post Type 
 */
function wpyog_register_products_cpt() {
    // change 'wpyog_products' to whatever your text_domain is.
    
    /** Setup labels */
    $labels = array(
        'name'               => x_( 'Products', 'wpyog_products' ),
        'singular_name'      => x_( 'Product', 'wpyog_products' ),
        'add_new'            => x_( 'Add New', 'wpyog_products' ),
        'all_items'          => x_( 'All Products', 'wpyog_products' ),
        'add_new_item'       => x_( 'Add New Product', 'wpyog_products' ),
        'edit_item'          => x_( 'Edit Product', 'wpyog_products' ),
        'new_item'           => x_( 'New Product', 'wpyog_products' ),
        'view_item'          => x_( 'View Product', 'wpyog_products' ),
        'search_items'       => x_( 'Search Products', 'wpyog_products' ),
        'not_found'          => x_( 'No Products found', 'wpyog_products' ),
        'not_found_in_trash' => x_( 'No Products found in trash', 'wpyog_products' ),
        'parent_item_colon'  => x_( 'Parent Product:', 'wpyog_products' ),
        'menu_name'          => x_( 'Products', 'wpyog_products' )
    );
    
    /** Setup args */
    $args = array(
        'labels'              => $labels,
        'description'         => x_( 'Products post type', 'wpyog_products' ),
        'public'              => true,
        'menu_position'       => 20,
        'supports'            => array( 'title', 'editor', 'excerpt', 'page-attributes', ),
        'has_archive'         => 'books',
        'rewrite'             => array( 'slug' => 'product', ),
    );
    
    /** Register Custom Post Type */
    register_post_type( 'wpyog_products', $args );
}

So if I wanted to change the label, add function inside function.php file:

add_action( 'registered_post_type', 'wpyog_products_label_rename', 10, 2 );
/**
 * Modify registered post type
 *
 * @param string $post_type Registered post type name.
 * @param array $args Array of post type parameters.
 */
function wpyog_products_label_rename( $post_type, $args ) {
    if ( 'wpyog_products' === $post_type ) {
        global $wp_post_types;
$args->labels->menu_name = __( 'Custom Products', 'wpyog_products' );
        $args->exclude_from_search = false;
        $wp_post_types[ $post_type ] = $args;
$wp_post_types['wpyog_products']->exclude_from_search = false;
    }



So if I wanted to change the taxonomy slug, add function inside function.php file:

function wpyog_modify_taxonomy() {
$product_category_args = get_taxonomy( 'kbe_taxonomy' ); // returns an object
// make changes to the args
// in this example there are three changes
// again, note that it's an object
$product_category_args->show_admin_column = true;
$product_category_args->rewrite['slug'] = 'product_resources';
$product_category_args->rewrite['with_front'] = true;

// re-register the taxonomy
register_taxonomy( 'kbe_taxonomy', 'product_resources', (array) $product_category_args );
}

add_action( 'init', 'wpyog_modify_taxonomy', 11 );

Monday, 11 June 2018

How to change integer value in number format jQuery

Here are simple way you can change integer value in number format on key up using jQuery

Html Code:
<input type="text" name="amount" class="required" value="">

jQuery Code:
<script>
jQuery.noConflict();
jQuery(document).ready( function($){ 
$(document).on('keyup', 'input.required', function(event){
if($(this).hasClass('field-error')){
$(this).css('border-color', '#83A4C5');
$(this).removeClass('field-error');
}   
var selection = window.getSelection().toString();
if ( selection !== '' ) {
return;
}           
// When the arrow keys are pressed, abort it.
if ( $.inArray( event.keyCode, [38,40,37,39] ) !== -1 ) {
return;
}      
var $this = $( this );           
// Get the value.
var input = $this.val();            
var input = input.replace(/[\D\s\._\-]+/g, "");
input = input ? parseInt( input, 10 ) : 0;
$this.val( function() {
return ( input === 0 ) ? "" : input.toLocaleString( "en-US" );
} );      
});
});
</script>

Monday, 23 April 2018

How to implement routing in Nodejs

A route is a mapping from a url to an object.It handles HTTP client requests.

Basic Routing

Hope you have install and have basic knowledge Express module.
npm install express

Note: Above command download the required express modules and install them.

Here is our Server file.

var express = require( 'express' );
var app = express();
//Creating Router() object
var router = express.Router();
// Provide all routes here, this is for Home page.
router.get("/",function(req,res){
  res.json({"message" : "Hello World"});
});
app.use("/",router);
// Listen to this Port
app.listen(3000,function(){
  console.log("Live at Port 3000");
});

Code Explanation:

1. In our first line of code, include the "express module."
2. Create object of the express module.
3. Creating a callback function. This function call when you hit url from browser http://localhost:3000 .It send the string 'Hello World' to the web page.
4. The 'res' parameter is used to send content back to the web page.
5. Create object of route() module. And handle get request.

Basic middleware routing :

// Router middleware, mentioned it before defining routes.

router.use(function(req,res,next) {
  console.log("/" + req.method);
  next();
});

Create a router file named route.js in the app directory, with the following content:

var express = require('express')
var router = express.Router()

// middleware that is specific to this router
router.use(function timeLog (req, res, next) {
  console.log('Time: ', Date.now())
  next()
})
// define the home page route
router.get('/', function (req, res) {
  res.send('Home page content')
})
// define the about route
router.get('/about', function (req, res) {
  res.send('About page content')
})
module.exports = router

Load the router module in the app:

var routes = require('./route');
app.use('/child', routes)

Now make a requests to /child and /child/about