How to add widget in wordpress

go to theme directory then open function.php file then find function function twentyeleven_widgets_init()
add following code inside it:
register_sidebar( array(
‘name’ => __( ‘Main Sidebar’, ‘twentyeleven’ ),
‘id’ => ‘sidebar-1’,
‘before_widget’ => ‘

“,
‘before_title’ => ‘

‘,
‘after_title’ => ‘

‘,
) );

then call it by following code:
if(is_active_sidebar(f-1)):?>

Upload images to custom folder in wordpress

upload images to custom folder in wordpress

* in your functions.php file put the below code:
*** here you can change the uploads_img folder name to anything

function ashique_custom_image_dir( $pathdata ) {
$subdir = ‘/uploads_img’.$pathdata[‘subdir’];
$pathdata[‘path’] = str_replace($pathdata[‘subdir’], $subdir, $pathdata[‘path’]);
$pathdata[‘url’] = str_replace($pathdata[‘subdir’], $subdir, $pathdata[‘url’]);
$pathdata[‘subdir’] = str_replace($pathdata[‘subdir’], $subdir, $pathdata[‘subdir’]);
return $pathdata;
}

add_filter( ‘upload_dir’, ‘ashique_custom_image_dir’ );

WordPress word cutter

<?php $project_page_id=get_page_by_path('interior-decoration')->ID;?>
<?php echo get_the_title($project_page_id);?>

<?php $fcon=get_post($project_page_id)->post_content; //echo substr($fcon,0,100);
$words = explode(" ", $fcon);
$first = join(" ", array_slice($words, 0, 17));
echo $first;
?>

<a class="fprmore" href="<?php echo get_page_link($project_page_id);?>">Read More</a>

Multiple rows insert in WordPress

----------------------------------------------------
$items         = [];
$values        = [];
$place_holders = [];
$query         = "INSERT INTO {$wpdb->prefix}table_name (col1, col2) VALUES ";
foreach ( $your_data_array_here as $key => $val ) {
    array_push( $values, $col1_value );
    array_push( $values, $col2_value );
    $place_holders[] = "('%d', '%d')";
}

$query .= implode( ', ', $place_holders );
$wpdb->query( $wpdb->prepare( "$query ", $values ) );

------------------------------------------------------
//set your key and data as per your needs.

Php mysql recursive function to delete all child nodes in one table

// first action:

// find the deepest nodes if have any

   $child_kit = [ ];
   get_child_dir_ids( $fd_id, $child_kit );

   $wpdb->delete(
       $wpdb->prefix . 'table_A',
           array( 'dir_id' => $fd_id, 'eid' => $eid ),
           array( '%d', '%d' )
   );
   $wpdb->delete(
       $wpdb->prefix . 'table_A',
           array( 'parent_id' => $fd_id, 'eid' => $eid ),
           array( '%d', '%d' )
   );

   //delete all child nodes now

   if ( count($child_kit) > 0 ) {
       $dir_id_to_be_deleted = implode( ",", $child_kit );
       $query = "DELETE FROM {$wpdb->prefix}table_A WHERE eid={$eid} AND parent_id IN($dir_id_to_be_deleted)";
       $wpdb->query($query);
   }

// second action:

function get_child_dir_ids( $parent_id, &$child_kit ) {
    global $wpdb;

    $query  = "SELECT dir_id FROM {$wpdb->prefix}table_A WHERE parent_id=" . $parent_id;
    $dir_id = $wpdb->get_var( $query );
    if ( is_null( $dir_id ) ) {
        return $child_kit;
    } else {
        $child_kit[] = $dir_id;
        get_child_dir_ids( $dir_id, $child_kit );
    }

}

*** i have shown it in wordpress way but you can manage it in any programming language or platform you like********************************************************